mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
chore: remove axios-instance and fix types for StrapiApp
This commit is contained in:
parent
b026f35fde
commit
db4036bc4d
@ -7,7 +7,9 @@ module.exports = {
|
||||
*
|
||||
* This gives you an opportunity to extend code.
|
||||
*/
|
||||
register({ strapi }) {},
|
||||
register(app) {
|
||||
console.log(app);
|
||||
},
|
||||
|
||||
/**
|
||||
* An asynchronous bootstrap function that runs before
|
||||
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* axios with a custom config.
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
||||
});
|
||||
|
||||
instance.interceptors.request.use(
|
||||
async (config) => {
|
||||
config.headers = {
|
||||
Authorization: `Bearer ${auth.getToken()}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
// whatever you want to do with the error
|
||||
if (error.response?.status === 401) {
|
||||
auth.clearAppStorage();
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
);
|
||||
|
||||
const wrapper = wrapAxiosInstance(instance);
|
||||
|
||||
export default wrapper;
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import pluginId from '../../pluginId';
|
||||
|
||||
type InitializerProps = {
|
||||
|
@ -7,6 +7,6 @@
|
||||
import React from 'react';
|
||||
import { Puzzle } from '@strapi/icons';
|
||||
|
||||
const PluginIcon: React.VoidFunctionComponent = () => <Puzzle />;
|
||||
const PluginIcon = () => <Puzzle />;
|
||||
|
||||
export default PluginIcon;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
||||
|
||||
import pluginPkg from '../../package.json';
|
||||
import pluginId from './pluginId';
|
||||
import Initializer from './components/Initializer';
|
||||
@ -7,7 +8,7 @@ import PluginIcon from './components/PluginIcon';
|
||||
const name = pluginPkg.strapi.name;
|
||||
|
||||
export default {
|
||||
register(app) {
|
||||
register(app: any) {
|
||||
app.addMenuLink({
|
||||
to: `/plugins/${pluginId}`,
|
||||
icon: PluginIcon,
|
||||
@ -38,12 +39,13 @@ export default {
|
||||
app.registerPlugin(plugin);
|
||||
},
|
||||
|
||||
bootstrap(app) {},
|
||||
async registerTrads(app) {
|
||||
bootstrap(app: any) {},
|
||||
|
||||
async registerTrads(app: any) {
|
||||
const { locales } = app;
|
||||
|
||||
const importedTrads = await Promise.all(
|
||||
locales.map((locale) => {
|
||||
(locales as any[]).map((locale) => {
|
||||
return import(`./translations/${locale}.json`)
|
||||
.then(({ default: data }) => {
|
||||
return {
|
||||
|
@ -11,7 +11,7 @@ import { NotFound } from '@strapi/helper-plugin';
|
||||
import pluginId from '../../pluginId';
|
||||
import HomePage from '../HomePage';
|
||||
|
||||
const App: React.VoidFunctionComponent = () => {
|
||||
const App = () => {
|
||||
return (
|
||||
<div>
|
||||
<Switch>
|
||||
|
@ -7,7 +7,7 @@
|
||||
import React from 'react';
|
||||
import pluginId from '../../pluginId';
|
||||
|
||||
const HomePage: React.VoidFunctionComponent = () => {
|
||||
const HomePage = () => {
|
||||
return (
|
||||
<div>
|
||||
<h1>{pluginId}'s HomePage</h1>
|
||||
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* axios with a custom config.
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
||||
});
|
||||
|
||||
instance.interceptors.request.use(
|
||||
async (config) => {
|
||||
config.headers = {
|
||||
Authorization: `Bearer ${auth.getToken()}`,
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
// whatever you want to do with the error
|
||||
if (error.response?.status === 401) {
|
||||
auth.clearAppStorage();
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
);
|
||||
|
||||
const wrapper = wrapAxiosInstance(instance);
|
||||
|
||||
export default wrapper;
|
@ -12,7 +12,6 @@
|
||||
"@strapi/design-system": "^1.6.3",
|
||||
"@strapi/helper-plugin": "^4.6.0",
|
||||
"@strapi/icons": "^1.6.3",
|
||||
"axios": "^1.2.2",
|
||||
"prop-types": "^15.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -11,7 +11,6 @@
|
||||
"@strapi/design-system": "^1.6.3",
|
||||
"@strapi/helper-plugin": "^4.6.0",
|
||||
"@strapi/icons": "^1.6.3",
|
||||
"axios": "^1.2.2",
|
||||
"prop-types": "^15.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user