diff --git a/docs/3.x.x/en/plugins/advanced.md b/docs/3.x.x/en/plugins/advanced.md index 37defb0f84..80ffc15bcf 100644 --- a/docs/3.x.x/en/plugins/advanced.md +++ b/docs/3.x.x/en/plugins/advanced.md @@ -773,7 +773,7 @@ import reducer from './reducer'; export class FooPage extends React.Component { componentWillReceiveProps(nextProps) { if (this.props.error !== nextProps.error && nextProps.error) { - window.Strapi.notification.error(nextProps.errorMessage); + strapi.notification.error(nextProps.errorMessage); } } diff --git a/packages/strapi-admin/.gitignore b/packages/strapi-admin/.gitignore index f73a805285..8f9cf76d0b 100644 --- a/packages/strapi-admin/.gitignore +++ b/packages/strapi-admin/.gitignore @@ -1,9 +1,9 @@ # Don't check auto-generated stuff into git coverage -build node_modules -stats.json +build plugins.json +stats.json package-lock.json # Cruft diff --git a/packages/strapi-admin/admin/src/app.js b/packages/strapi-admin/admin/src/app.js index 4dffc00bb6..c75a5d4f38 100755 --- a/packages/strapi-admin/admin/src/app.js +++ b/packages/strapi-admin/admin/src/app.js @@ -25,6 +25,16 @@ import { pluginLoaded, updatePlugin } from 'containers/App/actions'; import configureStore from './store'; import { translationMessages, languages } from './i18n'; +// Retrieve remote and backend URLs. +const remoteURL = process.env.REMOTE_URL || 'http://localhost:1337/admin'; +const backendURL = process.env.BACKEND_URL || 'http://localhost:1337'; + +window.strapi = { + remoteURL, + backendURL, + languages, +}; + // Create redux store with history const initialState = {}; const history = createHistory({ @@ -70,11 +80,7 @@ window.onload = function onLoad() { // Don't inject plugins in development mode. if (window.location.port !== '4000') { - const uri = window.location.href.indexOf('/admin') !== -1 ? - `${window.location.origin}/admin` : - window.location.origin; - - fetch(`${process.env.ADMIN_URL !== null ? process.env.ADMIN_URL : uri}/config/plugins.json`) + fetch(`${remoteURL}/config/plugins.json`) .then(response => { return response.json(); }) @@ -140,10 +146,7 @@ const displayNotification = (message, status) => { store.dispatch(showNotification(message, status)); }; -const port = window.Strapi && window.Strapi.port ? window.Strapi.port : 1337; -const apiUrl = window.Strapi && window.Strapi.apiUrl ? window.Strapi.apiUrl : `http://localhost:${port}`; - -window.Strapi = { +window.strapi = Object.assign(window.strapi, { registerPlugin, notification: { success: (message) => { @@ -159,8 +162,6 @@ window.Strapi = { displayNotification(message, 'info'); }, }, - port, - apiUrl, refresh: (pluginId) => ({ translationMessages: (translationMessagesUpdated) => { render(merge({}, translationMessages, translationMessagesUpdated)); @@ -170,8 +171,7 @@ window.Strapi = { }, }), router: history, - languages, -}; +}); const dispatch = store.dispatch; export { diff --git a/packages/strapi-admin/admin/src/containers/ListPluginsPage/saga.js b/packages/strapi-admin/admin/src/containers/ListPluginsPage/saga.js index 5ca3a829ee..1841bb9444 100644 --- a/packages/strapi-admin/admin/src/containers/ListPluginsPage/saga.js +++ b/packages/strapi-admin/admin/src/containers/ListPluginsPage/saga.js @@ -21,7 +21,7 @@ export function* deletePlugin() { } catch(error) { yield put(deletePluginSucceeded()); - window.Strapi.notification.error('app.components.listPluginsPage.deletePlugin.error'); + strapi.notification.error('app.components.listPluginsPage.deletePlugin.error'); } } // Individual exports for testing diff --git a/packages/strapi-generate-new/package.json b/packages/strapi-generate-new/package.json index 10bc381311..6d15a43ce1 100755 --- a/packages/strapi-generate-new/package.json +++ b/packages/strapi-generate-new/package.json @@ -47,4 +47,4 @@ "npm": ">= 5.3.0" }, "license": "MIT" -} +} \ No newline at end of file diff --git a/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js b/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js index c2598a7c6c..f477076aa1 100755 --- a/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js +++ b/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js @@ -5,15 +5,34 @@ const _ = require('lodash'); const fs = require('fs'); const path = require('path'); - const webpack = require('webpack'); const pkg = require(path.resolve(process.cwd(), 'package.json')); const pluginId = pkg.name.replace(/^strapi-/i, ''); -let noPlugin = false; -let plugins = []; -let pluginFolders = {}; +// Define remote and backend URLs. +const URLs = { + remote: '', + backend: '' +}; + +const serverConfig = path.resolve(process.env.PWD, '..', 'config', 'environments', _.lowerCase(process.env.NODE_ENV), 'server.json'); + +try { + const server = require(serverConfig); + + URLs.remote = _.get(server, 'admin.remoteURL', null) ? _.get(server, 'admin.remoteURL', null) : `http://${_.get(server, 'host', 'localhost')}:${_.get(server, 'port', 1337)}/admin`; + URLs.backend = _.get(server, 'admin.backendURL', null) ? _.get(server, 'admin.backendURL', null) : `http://${_.get(server, 'host', 'localhost')}:${_.get(server, 'port', 1337)}`; +} catch (e) { + throw new Error('Impossible to open ' + serverConfig); +} + +// Load plugins into the same build in development mode. +const plugins = { + exist: false, + src: [], + folders: {} +}; if (process.env.npm_lifecycle_event === 'start') { try { @@ -23,33 +42,23 @@ if (process.env.npm_lifecycle_event === 'start') { fs.accessSync(path.resolve(process.env.PWD, '..', 'api'), fs.constants.R_OK); // Allow app without plugins. - noPlugin = true; + plugins.exist = true; } catch (e) { throw new Error(`You need to start the WebPack server from the /admin directory in a Strapi's project.`); } } - plugins = process.env.IS_ADMIN === 'true' && !noPlugin ? fs.readdirSync(path.resolve(process.env.PWD, '..', 'plugins')) - .filter(x => x[0] !== '.') : []; + // Read `plugins` directory. + plugins.src = process.env.IS_ADMIN === 'true' && !plugins.exist ? fs.readdirSync(path.resolve(process.env.PWD, '..', 'plugins')).filter(x => x[0] !== '.') : []; - pluginFolders = plugins.reduce((acc, current) => { + // Construct object of plugin' paths. + plugins.folders = plugins.src.reduce((acc, current) => { acc[current] = path.resolve(process.env.PWD, '..', 'plugins', current, 'node_modules', 'strapi-helper-plugin', 'lib', 'src'); return acc; }, {}); } -let adminURL = null; - -try { - const server = require(path.resolve(process.env.PWD, '..', 'config', 'environments', _.lowerCase(process.env.NODE_ENV), 'server.json')); - - adminURL = _.get(server, 'admin.url', null); -} catch (e) { - // Silent -} - - module.exports = (options) => ({ entry: options.entry, output: Object.assign({ // Compile into js/build.js @@ -83,8 +92,8 @@ module.exports = (options) => ({ }, }, include: [path.join(process.cwd(), 'admin', 'src')] - .concat(plugins.reduce((acc, current) => { - acc.push(path.resolve(process.env.PWD, '..', 'plugins', current, 'admin', 'src'), pluginFolders[current]); + .concat(plugins.src.reduce((acc, current) => { + acc.push(path.resolve(process.env.PWD, '..', 'plugins', current, 'admin', 'src'), plugins.folders[current]); return acc; }, [])) @@ -174,7 +183,8 @@ module.exports = (options) => ({ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV), - ADMIN_URL: JSON.stringify(adminURL), + REMOTE_URL: JSON.stringify(URLs.remote), + BACKEND_URL: JSON.stringify(URLs.backend), }, }), new webpack.NamedModulesPlugin() diff --git a/packages/strapi-helper-plugin/lib/src/app.js b/packages/strapi-helper-plugin/lib/src/app.js index 44ff20c1b5..2c30a09924 100755 --- a/packages/strapi-helper-plugin/lib/src/app.js +++ b/packages/strapi-helper-plugin/lib/src/app.js @@ -41,11 +41,11 @@ const pluginId = pluginPkg.name.replace( ); const pluginName = pluginPkg.strapi.name; const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; -const apiUrl = window.Strapi && `${window.Strapi.apiUrl}/${pluginId}`; -const router = window.Strapi.router; +const apiUrl = `${strapi.backendURL}/${pluginId}`; +const router = strapi.router; // Create redux store with Strapi admin history -const store = configureStore({}, window.Strapi.router); +const store = configureStore({}, strapi.router); // Define the plugin root component function Comp(props) { @@ -61,10 +61,10 @@ 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) { + if (strapi) { System.import('./i18n').then(result => { const translationMessagesUpdated = result.translationMessages; - window.Strapi + strapi .refresh(pluginId) .translationMessages(translationMessagesUpdated); }); @@ -73,7 +73,7 @@ if (module.hot) { } // Register the plugin. -window.Strapi.registerPlugin({ +strapi.registerPlugin({ name: pluginPkg.strapi.name, icon: pluginPkg.strapi.icon, description: pluginDescription, diff --git a/packages/strapi-helper-plugin/lib/src/i18n.js b/packages/strapi-helper-plugin/lib/src/i18n.js index 076aacefaa..03b113bacf 100755 --- a/packages/strapi-helper-plugin/lib/src/i18n.js +++ b/packages/strapi-helper-plugin/lib/src/i18n.js @@ -34,7 +34,7 @@ const formatMessages = messages => reduce(messages, (result, value, key) => { */ const requireTranslations = language => { try { - return require(`translations/${language}.json`); // eslint-disable-line global-require + return require(`/translations/${language}.json`); // eslint-disable-line global-require } catch (error) { console.error(`Unable to load "${language}" translation for the plugin ${pluginId}. Please make sure "${language}.json" file exists in "pluginPath/admin/src/translations" folder.`); return false; @@ -44,7 +44,10 @@ const requireTranslations = language => { /** * Dynamically generate `translationsMessages object`. */ -const translationMessages = reduce(window.Strapi.languages, (result, language) => { + +console.log(window.strapi); + +const translationMessages = reduce(window.strapi.languages, (result, language) => { const obj = result; const messages = requireTranslations(language); obj[language] = formatMessages(messages); diff --git a/packages/strapi-helper-plugin/lib/src/utils/request.js b/packages/strapi-helper-plugin/lib/src/utils/request.js index 64d0ea09f9..7d572d317f 100755 --- a/packages/strapi-helper-plugin/lib/src/utils/request.js +++ b/packages/strapi-helper-plugin/lib/src/utils/request.js @@ -50,7 +50,7 @@ function formatQueryParams(params) { */ function serverRestartWatcher(response) { return new Promise((resolve, reject) => { - fetch(`${Strapi.apiUrl}/_health`, { + fetch(`${strapi.backendURL}/_health`, { method: 'HEAD', mode: 'no-cors', headers: { @@ -86,7 +86,7 @@ function serverRestartWatcher(response) { // Add parameters to url url = _.startsWith(url, '/') - ? `${Strapi.apiUrl}${url}` + ? `${strapi.backendURL}${url}` : url; if (options && options.params) { diff --git a/packages/strapi-plugin-content-manager/admin/src/components/SelectMany/index.js b/packages/strapi-plugin-content-manager/admin/src/components/SelectMany/index.js index a1e1dca40c..1e62d70f99 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/SelectMany/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/SelectMany/index.js @@ -58,7 +58,7 @@ class SelectMany extends React.Component { // eslint-disable-line react/prefer-s return { options }; }) .catch(() => { - window.Strapi.notification.error('An error occurred during relationship fetch.'); + strapi.notification.error('An error occurred during relationship fetch.'); }); } diff --git a/packages/strapi-plugin-content-manager/admin/src/components/SelectOne/index.js b/packages/strapi-plugin-content-manager/admin/src/components/SelectOne/index.js index d8b7412339..ac23a9ff31 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/SelectOne/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/SelectOne/index.js @@ -58,7 +58,7 @@ class SelectOne extends React.Component { // eslint-disable-line react/prefer-st return {options}; }) .catch(() => { - window.Strapi.notification.error('An error occurred during relationship fetch.'); + strapi.notification.error('An error occurred during relationship fetch.'); }); } diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/App/sagas.js b/packages/strapi-plugin-content-manager/admin/src/containers/App/sagas.js index d9504b950a..2d9abb8fdd 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/App/sagas.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/App/sagas.js @@ -10,17 +10,17 @@ import { makeSelectModels } from './selectors'; export function* modelEntriesGet(action) { try { - const requestUrl = `${window.Strapi.apiUrl}/content-manager/explorer/${action.modelName}/count`; + const requestUrl = `${strapi.backendURL}/content-manager/explorer/${action.modelName}/count`; const response = yield call(request, requestUrl, { method: 'GET' }); yield put(getModelEntriesSucceeded(response.count)); } catch(error) { - window.Strapi.notification.error('content-manager.error.model.fetch'); + strapi.notification.error('content-manager.error.model.fetch'); } } export const generateMenu = function () { - return request(`${window.Strapi.apiUrl}/content-manager/models`, { + return request(`${strapi.backendURL}/content-manager/models`, { method: 'GET', }) .then(response => generateSchema(response)) @@ -34,7 +34,7 @@ export const generateMenu = function () { }]; }) .catch((error) => { - window.Strapi.notification.error('content-manager.error.model.fetch'); + strapi.notification.error('content-manager.error.model.fetch'); throw Error(error); }); }; @@ -42,13 +42,13 @@ export const generateMenu = function () { export function* getModels() { try { const response = yield call(request, - `${window.Strapi.apiUrl}/content-manager/models`, { + `${strapi.backendURL}/content-manager/models`, { method: 'GET', }); yield put(loadedModels(response)); } catch (err) { - window.Strapi.notification.error('content-manager.error.model.fetch'); + strapi.notification.error('content-manager.error.model.fetch'); } } @@ -59,7 +59,7 @@ export function* modelsLoaded() { try { schema = generateSchema(models); } catch (err) { - window.Strapi.notification.error('content-manager.error.schema.generation'); + strapi.notification.error('content-manager.error.schema.generation'); throw new Error(err); } diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js index 81115d0d3b..a4d8b15520 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/index.js @@ -114,7 +114,7 @@ export class Edit extends React.Component { componentWillReceiveProps(nextProps) { if (this.props.editSuccess !== nextProps.editSuccess) { if (!isEmpty(this.props.location.search)) { - window.Strapi.notification.success('content-manager.success.record.save'); + strapi.notification.success('content-manager.success.record.save'); router.push(replace(this.props.location.search, '?redirectUrl=', '')); } else { router.push(replace(this.props.location.pathname, 'create', '')); diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js index f08bbf006b..e870f816a6 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/Edit/sagas.js @@ -23,7 +23,7 @@ export function* getRecord(params) { const currentModelName = yield select(makeSelectCurrentModelName()); try { - const requestUrl = `${window.Strapi.apiUrl}/content-manager/explorer/${currentModelName}/${params.id}`; + const requestUrl = `${strapi.backendURL}/content-manager/explorer/${currentModelName}/${params.id}`; // Call our request helper (see 'utils/request') const response = yield request(requestUrl, { @@ -32,7 +32,7 @@ export function* getRecord(params) { yield put(recordLoaded(response)); } catch (err) { - window.Strapi.notification.error('content-manager.error.record.fetch'); + strapi.notification.error('content-manager.error.record.fetch'); } } @@ -51,7 +51,7 @@ export function* editRecord() { const id = isCreating ? '' : recordCleaned.id; try { - const requestUrl = `${window.Strapi.apiUrl}/content-manager/explorer/${currentModelName}/${id}`; + const requestUrl = `${strapi.backendURL}/content-manager/explorer/${currentModelName}/${id}`; // Call our request helper (see 'utils/request') yield call(request, requestUrl, { @@ -60,17 +60,17 @@ export function* editRecord() { }); yield put(recordEdited()); - window.Strapi.notification.success('content-manager.success.record.save'); + strapi.notification.success('content-manager.success.record.save'); } catch (err) { yield put(recordEditError()); - window.Strapi.notification.error(isCreating ? 'content-manager.error.record.create' : 'content-manager.error.record.update'); + strapi.notification.error(isCreating ? 'content-manager.error.record.create' : 'content-manager.error.record.update'); } } export function* deleteRecord({ id, modelName }) { function* httpCall(id, modelName) { try { - const requestUrl = `${window.Strapi.apiUrl}/content-manager/explorer/${modelName}/${id}`; + const requestUrl = `${strapi.backendURL}/content-manager/explorer/${modelName}/${id}`; // Call our request helper (see 'utils/request') yield call(request, requestUrl, { @@ -78,13 +78,13 @@ export function* deleteRecord({ id, modelName }) { }); yield put(recordDeleted(id)); - window.Strapi.notification.success('content-manager.success.record.delete'); + strapi.notification.success('content-manager.success.record.delete'); // Redirect to the list page. router.push(`/plugins/content-manager/${modelName}`); } catch (err) { yield put(recordDeleteError()); - window.Strapi.notification.error('content-manager.error.record.delete'); + strapi.notification.error('content-manager.error.record.delete'); } } diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/List/sagas.js b/packages/strapi-plugin-content-manager/admin/src/containers/List/sagas.js index fda7e516a0..b4776238d0 100755 --- a/packages/strapi-plugin-content-manager/admin/src/containers/List/sagas.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/List/sagas.js @@ -41,7 +41,7 @@ export function* getRecords() { }; try { - const requestUrl = `${window.Strapi.apiUrl}/content-manager/explorer/${currentModel}`; + const requestUrl = `${strapi.backendURL}/content-manager/explorer/${currentModel}`; // Call our request helper (see 'utils/request') const response = yield call(request, requestUrl, { method: 'GET', @@ -50,7 +50,7 @@ export function* getRecords() { yield put(loadedRecord(response)); } catch (err) { - window.Strapi.notification.error('content-manager.error.records.fetch'); + strapi.notification.error('content-manager.error.records.fetch'); } } @@ -60,12 +60,12 @@ export function* getCount() { try { const response = yield call( request, - `${window.Strapi.apiUrl}/content-manager/explorer/${currentModel}/count`, + `${strapi.backendURL}/content-manager/explorer/${currentModel}/count`, ); yield put(loadedCount(response.count)); } catch (err) { - window.Strapi.notification.error('content-manager.error.records.count'); + strapi.notification.error('content-manager.error.records.count'); } } diff --git a/packages/strapi-plugin-content-manager/admin/src/utils/request.js b/packages/strapi-plugin-content-manager/admin/src/utils/request.js index e988ada348..118c3bfb57 100644 --- a/packages/strapi-plugin-content-manager/admin/src/utils/request.js +++ b/packages/strapi-plugin-content-manager/admin/src/utils/request.js @@ -59,7 +59,7 @@ export default function request(url, options = {}) { // Add parameters to url url = _.startsWith(url, '/') - ? `${Strapi.apiUrl}${url}` + ? `${strapi.backendURL}${url}` : url; if (options && options.params) { diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/sagas.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/sagas.js index d70a855d16..1bbc9a890e 100755 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/App/sagas.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/App/sagas.js @@ -13,11 +13,11 @@ export function* deleteContentType(action) { if (action.updateLeftMenu) { action.updatePlugin('content-manager', 'leftMenuSections', action.leftMenuContentTypes); } - window.Strapi.notification.success('content-type-builder.notification.success.contentTypeDeleted'); + strapi.notification.success('content-type-builder.notification.success.contentTypeDeleted'); } } catch(error) { - window.Strapi.notification.error('content-type-builder.notification.error.message'); + strapi.notification.error('content-type-builder.notification.error.message'); } } @@ -28,7 +28,7 @@ export function* fetchModels() { yield put(modelsFetchSucceeded(data)); } catch(error) { - window.Strapi.notification.error('content-type-builder.notification.error.message'); + strapi.notification.error('content-type-builder.notification.error.message'); } } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/sagas.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/sagas.js index 9a263f6935..fb49163e7c 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/sagas.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/sagas.js @@ -54,10 +54,10 @@ export function* editContentType(action) { leftMenuContentTypes[0].links = sortBy(leftMenuContentTypes[0].links, 'label'); action.context.updatePlugin('content-manager', 'leftMenuSections', leftMenuContentTypes); } - window.Strapi.notification.success('content-type-builder.notification.success.message.contentType.edit'); + strapi.notification.success('content-type-builder.notification.success.message.contentType.edit'); } } catch(error) { - window.Strapi.notification.error(error); + strapi.notification.error(error); } } @@ -69,7 +69,7 @@ export function* fetchConnections() { yield put(connectionsFetchSucceeded(data)); } catch(error) { - window.Strapi.notification.error('content-type-builder.notification.error.message'); + strapi.notification.error('content-type-builder.notification.error.message'); } } @@ -83,7 +83,7 @@ export function* fetchContentType(action) { yield put(contentTypeFetchSucceeded(data)); } catch(error) { - window.Strapi.notification.error('content-type-builder.notification.error.message'); + strapi.notification.error('content-type-builder.notification.error.message'); } } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js index bca7853a64..2e494b9a6b 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/HomePage/index.js @@ -44,7 +44,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre handleButtonClick = () => { if (storeData.getIsModelTemporary()) { - window.Strapi.notification.info('content-type-builder.notification.info.contentType.creating.notSaved'); + strapi.notification.info('content-type-builder.notification.info.contentType.creating.notSaved'); } else { this.toggleModal(); } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js index 18a746444f..3895dc024e 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/index.js @@ -135,7 +135,7 @@ export class ModelPage extends React.Component { // eslint-disable-line react/pr handleAddLinkClick = () => { if (storeData.getIsModelTemporary()) { - window.Strapi.notification.info('content-type-builder.notification.info.contentType.creating.notSaved'); + strapi.notification.info('content-type-builder.notification.info.contentType.creating.notSaved'); } else { this.toggleModal(); } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/sagas.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/sagas.js index ab5cf18e52..37bca9fee7 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/sagas.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ModelPage/sagas.js @@ -43,7 +43,7 @@ export function* getTableExistance() { yield put(checkIfTableExistsSucceeded(tableExists)); } catch(error) { - window.Strapi.notification.error('An error occured'); + strapi.notification.error('An error occured'); } } @@ -58,7 +58,7 @@ export function* fetchModel(action) { yield put(unsetButtonLoader()); } catch(error) { - window.Strapi.notification.error('An error occured'); + strapi.notification.error('An error occured'); } } @@ -116,10 +116,10 @@ export function* submitChanges(action) { action.context.updatePlugin('content-manager', 'leftMenuSections', leftMenuContentTypes); } - window.Strapi.notification.success('content-type-builder.notification.success.message.contentType.create'); + strapi.notification.success('content-type-builder.notification.success.message.contentType.create'); } else { - window.Strapi.notification.success('content-type-builder.notification.success.message.contentType.edit'); + strapi.notification.success('content-type-builder.notification.success.message.contentType.edit'); } yield put(submitActionSucceeded()); @@ -130,7 +130,7 @@ export function* submitChanges(action) { } } catch(error) { - window.Strapi.notification.error(error); + strapi.notification.error(error); } } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/requirements.js b/packages/strapi-plugin-content-type-builder/admin/src/requirements.js index 3d336a6b54..c4078c45d0 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/requirements.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/requirements.js @@ -1,7 +1,7 @@ import request from 'utils/request'; const shouldRenderCompo = (plugin) => new Promise((resolve, reject) => { - request('/content-type-builder/autoReload') + request(`${strapi.backendURL}/content-type-builder/autoReload`) .then(response => { plugin.preventComponentRendering = !response.autoReload; plugin.blockerComponentProps = { @@ -16,5 +16,4 @@ const shouldRenderCompo = (plugin) => new Promise((resolve, reject) => { .catch(err => reject(err)); }); - export default shouldRenderCompo; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/utils/storeData.js b/packages/strapi-plugin-content-type-builder/admin/src/utils/storeData.js index 3b8e98a068..779d31db3d 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/utils/storeData.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/utils/storeData.js @@ -47,7 +47,7 @@ export const storeData = { return localStorage.setItem(contentType, stringify(data)); } - return window.Strapi.notification.info('This plugin is optimized with your localStorage'); + return strapi.notification.info('This plugin is optimized with your localStorage'); }, setMenu(data, menu = MENU) { @@ -55,7 +55,7 @@ export const storeData = { return localStorage.setItem(menu, stringify(data)); } - return window.Strapi.notification.info('This plugin is optimized with your localStorage'); + return strapi.notification.info('This plugin is optimized with your localStorage'); }, setModel(data, model = MODEL) { @@ -63,7 +63,7 @@ export const storeData = { return localStorage.setItem(model, stringify(data)); } - return window.Strapi.notification.info('This plugin is optimized with your localStorage'); + return strapi.notification.info('This plugin is optimized with your localStorage'); }, setIsModelTemporary(isModelTemporay = IS_MODEL_TEMPORARY) { @@ -71,6 +71,6 @@ export const storeData = { return localStorage.setItem(isModelTemporay, true); } - return window.Strapi.notification.info('This plugin is optimized with your localStorage'); + return strapi.notification.info('This plugin is optimized with your localStorage'); }, }; diff --git a/packages/strapi-plugin-settings-manager/admin/src/containers/App/sagas.js b/packages/strapi-plugin-settings-manager/admin/src/containers/App/sagas.js index a679447a0d..e2066b9e47 100755 --- a/packages/strapi-plugin-settings-manager/admin/src/containers/App/sagas.js +++ b/packages/strapi-plugin-settings-manager/admin/src/containers/App/sagas.js @@ -17,7 +17,7 @@ export function* fetchMenu() { yield put(fetchMenuSucceeded(data)); } catch(err) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -33,7 +33,7 @@ export function* fetchEnvironments() { yield put(environmentsFetchSucceeded(data)); } catch(error) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } diff --git a/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/index.js b/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/index.js index 488a8e99fd..73201507e7 100755 --- a/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/index.js +++ b/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/index.js @@ -261,7 +261,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre const body = this.sendUpdatedParams(isCreatingNewFields); const formErrors = checkFormValidity(body, this.props.home.formValidations); - if (isEmpty(body)) return window.Strapi.notification.info('settings-manager.strapi.notification.info.settingsEqual'); + if (isEmpty(body)) return strapi.notification.info('settings-manager.strapi.notification.info.settingsEqual'); if (isEmpty(formErrors)) { this.props.editSettings(body, apiUrl); } else { @@ -276,7 +276,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre if (isEmpty(body)) { this.props.closeModal(); - return window.Strapi.notification.info('settings-manager.strapi.notification.info.settingsEqual'); + return strapi.notification.info('settings-manager.strapi.notification.info.settingsEqual'); } @@ -291,7 +291,7 @@ export class HomePage extends React.Component { // eslint-disable-line react/pre handleLanguageDelete = (languaToDelete) => this.props.languageDelete(languaToDelete); handleDatabaseDelete = (dbName) => { - window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseDelete'); + strapi.notification.success('settings-manager.strapi.notification.success.databaseDelete'); this.props.databaseDelete(dbName, this.props.match.params.env); } diff --git a/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/sagas.js b/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/sagas.js index 012d717c4e..d4f25e0932 100755 --- a/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/sagas.js +++ b/packages/strapi-plugin-settings-manager/admin/src/containers/HomePage/sagas.js @@ -53,14 +53,14 @@ export function* editDatabase(action) { const resp = yield call(request, requestUrl, opts, true); if (resp.ok) { - window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseEdit'); + strapi.notification.success('settings-manager.strapi.notification.success.databaseEdit'); yield put(databaseActionSucceeded()); } } catch(error) { const formErrors = map(error.response.payload.message, err => ({ target: err.target, errors: map(err.messages, mess => ({ id: `settings-manager.${mess.id}`})) })); yield put(databaseActionError(formErrors)); - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -72,11 +72,11 @@ export function* deleteDatabase(action) { const resp = yield call(request, requestUrl, opts, true); if (resp.ok) { - window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseDeleted'); + strapi.notification.success('settings-manager.strapi.notification.success.databaseDeleted'); } } catch(error) { yield put(databaseActionError([])); - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -90,11 +90,11 @@ export function* deleteLanguage(action) { const resp = yield call(request, requestUrl, opts, true); if (resp.ok) { - window.Strapi.notification.success('settings-manager.strapi.notification.success.languageDelete'); + strapi.notification.success('settings-manager.strapi.notification.success.languageDelete'); } } catch(error) { yield put(languageActionError()); - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -108,7 +108,7 @@ export function* fetchConfig(action) { const data = yield call(request, requestUrl, opts); yield put(configFetchSucceded(data)); } catch(error) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -127,7 +127,7 @@ export function* fetchDatabases(action) { ]; yield put(databasesFetchSucceeded(listDatabasesData, appDatabaseData)); } catch(error) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -145,7 +145,7 @@ export function* fetchLanguages() { ]; yield put(languagesFetchSucceeded(appLanguagesData, listLanguagesData)); } catch(error) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -174,12 +174,12 @@ export function* postLanguage() { const resp = yield call(request, requestUrl, opts, true); if (resp.ok) { - window.Strapi.notification.success('settings-manager.strapi.notification.success.languageAdd'); + strapi.notification.success('settings-manager.strapi.notification.success.languageAdd'); yield put(languageActionSucceeded()); } } catch(error) { yield put(languageActionError()); - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -201,7 +201,7 @@ export function* postDatabase(action) { if (resp.ok) { yield put(databaseActionSucceeded()); - window.Strapi.notification.success('settings-manager.strapi.notification.success.databaseAdd'); + strapi.notification.success('settings-manager.strapi.notification.success.databaseAdd'); } } catch(error) { const formErrors = map(error.response.payload.message, (err) => { @@ -213,7 +213,7 @@ export function* postDatabase(action) { yield put(databaseActionError(formErrors)); - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } @@ -230,12 +230,12 @@ export function* settingsEdit(action) { const resp = yield call(request, requestUrl, opts, true); if (resp.ok) { - window.Strapi.notification.success('settings-manager.strapi.notification.success.settingsEdit'); + strapi.notification.success('settings-manager.strapi.notification.success.settingsEdit'); yield put(editSettingsSucceeded()); yield put(unsetLoader()); } } catch(error) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); yield put(unsetLoader()); } } @@ -251,7 +251,7 @@ export function* fetchSpecificDatabase(action) { yield put(specificDatabaseFetchSucceeded(data)); } catch(error) { - window.Strapi.notification.error('settings-manager.strapi.notification.error'); + strapi.notification.error('settings-manager.strapi.notification.error'); } } diff --git a/packages/strapi-plugin-settings-manager/admin/src/utils/request.js b/packages/strapi-plugin-settings-manager/admin/src/utils/request.js index 35a38ed0a2..75202320e3 100755 --- a/packages/strapi-plugin-settings-manager/admin/src/utils/request.js +++ b/packages/strapi-plugin-settings-manager/admin/src/utils/request.js @@ -52,7 +52,7 @@ function formatQueryParams(params) { */ function serverRestartWatcher(response) { return new Promise((resolve) => { - fetch(`${Strapi.apiUrl}/_health`, { + fetch(`${strapi.backendURL}/_health`, { method: 'HEAD', mode: 'no-cors', headers: { @@ -90,7 +90,7 @@ export default function request(url, options, shouldWatchServerRestart = false) // Add parameters to url let urlFormatted = startsWith(url, '/') - ? `${Strapi.apiUrl}${url}` + ? `${strapi.backendURL}${url}` : url; if (optionsObj && optionsObj.params) { diff --git a/packages/strapi/lib/core/plugins.js b/packages/strapi/lib/core/plugins.js index 75291634a8..31af3c2580 100644 --- a/packages/strapi/lib/core/plugins.js +++ b/packages/strapi/lib/core/plugins.js @@ -66,8 +66,6 @@ module.exports = function() { }, {}) })); - console.log(strapi.admin); - fs.writeFileSync(sourcePath, JSON.stringify(data, null, 2), 'utf8'); fs.writeFileSync(buildPath, JSON.stringify(data), 'utf8'); diff --git a/packages/strapi/package.json b/packages/strapi/package.json index 2774d8bc7e..bcd36ed117 100755 --- a/packages/strapi/package.json +++ b/packages/strapi/package.json @@ -86,4 +86,4 @@ }, "preferGlobal": true, "license": "MIT" -} +} \ No newline at end of file