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.
|
* This gives you an opportunity to extend code.
|
||||||
*/
|
*/
|
||||||
register({ strapi }) {},
|
register(app) {
|
||||||
|
console.log(app);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An asynchronous bootstrap function that runs before
|
* 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';
|
import pluginId from '../../pluginId';
|
||||||
|
|
||||||
type InitializerProps = {
|
type InitializerProps = {
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Puzzle } from '@strapi/icons';
|
import { Puzzle } from '@strapi/icons';
|
||||||
|
|
||||||
const PluginIcon: React.VoidFunctionComponent = () => <Puzzle />;
|
const PluginIcon = () => <Puzzle />;
|
||||||
|
|
||||||
export default PluginIcon;
|
export default PluginIcon;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
import pluginPkg from '../../package.json';
|
import pluginPkg from '../../package.json';
|
||||||
import pluginId from './pluginId';
|
import pluginId from './pluginId';
|
||||||
import Initializer from './components/Initializer';
|
import Initializer from './components/Initializer';
|
||||||
@ -7,7 +8,7 @@ import PluginIcon from './components/PluginIcon';
|
|||||||
const name = pluginPkg.strapi.name;
|
const name = pluginPkg.strapi.name;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
register(app) {
|
register(app: any) {
|
||||||
app.addMenuLink({
|
app.addMenuLink({
|
||||||
to: `/plugins/${pluginId}`,
|
to: `/plugins/${pluginId}`,
|
||||||
icon: PluginIcon,
|
icon: PluginIcon,
|
||||||
@ -38,12 +39,13 @@ export default {
|
|||||||
app.registerPlugin(plugin);
|
app.registerPlugin(plugin);
|
||||||
},
|
},
|
||||||
|
|
||||||
bootstrap(app) {},
|
bootstrap(app: any) {},
|
||||||
async registerTrads(app) {
|
|
||||||
|
async registerTrads(app: any) {
|
||||||
const { locales } = app;
|
const { locales } = app;
|
||||||
|
|
||||||
const importedTrads = await Promise.all(
|
const importedTrads = await Promise.all(
|
||||||
locales.map((locale) => {
|
(locales as any[]).map((locale) => {
|
||||||
return import(`./translations/${locale}.json`)
|
return import(`./translations/${locale}.json`)
|
||||||
.then(({ default: data }) => {
|
.then(({ default: data }) => {
|
||||||
return {
|
return {
|
||||||
|
@ -11,7 +11,7 @@ import { NotFound } from '@strapi/helper-plugin';
|
|||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import HomePage from '../HomePage';
|
import HomePage from '../HomePage';
|
||||||
|
|
||||||
const App: React.VoidFunctionComponent = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Switch>
|
<Switch>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
|
|
||||||
const HomePage: React.VoidFunctionComponent = () => {
|
const HomePage = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>{pluginId}'s HomePage</h1>
|
<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/design-system": "^1.6.3",
|
||||||
"@strapi/helper-plugin": "^4.6.0",
|
"@strapi/helper-plugin": "^4.6.0",
|
||||||
"@strapi/icons": "^1.6.3",
|
"@strapi/icons": "^1.6.3",
|
||||||
"axios": "^1.2.2",
|
|
||||||
"prop-types": "^15.7.2"
|
"prop-types": "^15.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
"@strapi/design-system": "^1.6.3",
|
"@strapi/design-system": "^1.6.3",
|
||||||
"@strapi/helper-plugin": "^4.6.0",
|
"@strapi/helper-plugin": "^4.6.0",
|
||||||
"@strapi/icons": "^1.6.3",
|
"@strapi/icons": "^1.6.3",
|
||||||
"axios": "^1.2.2",
|
|
||||||
"prop-types": "^15.7.2"
|
"prop-types": "^15.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user