Fix plugin generator

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-12-30 08:55:34 +01:00
parent 576a603ed6
commit 349d384a7d
5 changed files with 46 additions and 71 deletions

View File

@ -0,0 +1,6 @@
module.exports = ({ env }) => ({
// autoOpen: false,
auth: {
secret: env('ADMIN_JWT_SECRET', 'example-token'),
},
});

View File

@ -1,25 +0,0 @@
/**
*
* This component is the skeleton around the actual pages, and should only
* contain code that should be seen on all pages. (e.g. navigation bar)
*
*/
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import { NotFound } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
import HomePage from '../HomePage';
const App = () => {
return (
<div>
<Switch>
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
<Route component={NotFound} />
</Switch>
</div>
);
};
export default App;

View File

@ -1,20 +0,0 @@
/*
*
* HomePage
*
*/
import React, { memo } from 'react';
// import PropTypes from 'prop-types';
import pluginId from '../../pluginId';
const HomePage = () => {
return (
<div>
<h1>{pluginId}&apos;s HomePage</h1>
<p>Happy coding</p>
</div>
);
};
export default memo(HomePage);

View File

@ -1,26 +0,0 @@
/**
*
* Initializer
*
*/
import { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import pluginId from '../../pluginId';
const Initializer = ({ setPlugin }) => {
const ref = useRef();
ref.current = setPlugin;
useEffect(() => {
ref.current(pluginId);
}, []);
return null;
};
Initializer.propTypes = {
setPlugin: PropTypes.func.isRequired,
};
export default Initializer;

View File

@ -0,0 +1,40 @@
/**
* axios with a custom config.
*/
import axios from 'axios';
import { auth } 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;
}
);
export default instance;