64 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-08-18 11:41:13 +02:00
/**
* app.js
*
2016-10-05 15:15:43 +02:00
* This is the entry file for the application,
* only setup and plugin code.
2016-08-18 11:41:13 +02:00
*/
2016-09-06 17:44:06 +02:00
import { browserHistory } from 'react-router';
2016-09-02 17:52:34 +02:00
import configureStore from './store';
2016-08-18 11:47:26 +02:00
2016-09-02 17:52:34 +02:00
// Create redux store with history
// this uses the singleton browserHistory provided by react-router
// Optionally, this could be changed to leverage a created history
// e.g. `const browserHistory = useRouterHistory(createBrowserHistory)();`
const initialState = {};
const store = configureStore(initialState, browserHistory);
// Set up the router, wrapping all Routes in the App component
import App from 'containers/App';
import createRoutes from './routes';
2016-10-12 12:07:26 +02:00
import { translationMessages } from './i18n';
2016-09-02 17:52:34 +02:00
2016-10-05 15:15:43 +02:00
// Plugin identifier based on the package.json `name` value
const pluginId = require('../package.json').name.replace(/^strapi-/i, '');
2016-09-02 17:52:34 +02:00
// Register the plugin
2016-10-04 17:49:40 +02:00
if (window.Strapi) {
window.Strapi.registerPlugin({
name: 'Settings Manager',
2016-10-05 15:15:43 +02:00
id: pluginId,
2016-10-04 17:49:40 +02:00
leftMenuLink: {
label: 'Settings Manager',
to: '/settings-manager',
},
mainComponent: App,
2016-10-05 13:48:49 +02:00
routes: createRoutes(store),
2016-10-12 12:07:26 +02:00
translationMessages,
});
}
// Hot reloadable translation json files
if (module.hot) {
// modules.hot.accept does not accept dynamic dependencies,
// have to be constants at compile-time
module.hot.accept('./i18n', () => {
if (window.Strapi) {
System.import('./i18n')
2016-11-18 16:18:29 +01:00
.then((result) => {
2016-10-12 12:07:26 +02:00
const translationMessagesUpdated = result.translationMessages;
window.Strapi.refresh(pluginId).translationMessages(translationMessagesUpdated);
});
}
2016-10-04 17:49:40 +02:00
});
}
2016-10-05 13:48:49 +02:00
2016-10-05 15:15:43 +02:00
// API
2016-10-20 19:27:43 +02:00
const apiUrl = window.Strapi && `${window.Strapi.apiUrl}/${pluginId}`;
2016-10-05 15:15:43 +02:00
2016-10-05 13:48:49 +02:00
// Export store
export {
store,
2016-10-05 15:15:43 +02:00
apiUrl,
};