diff --git a/admin/src/containers/ConfigPage/index.js b/admin/src/containers/ConfigPage/index.js index df00ec7..4a6ce4f 100644 --- a/admin/src/containers/ConfigPage/index.js +++ b/admin/src/containers/ConfigPage/index.js @@ -6,7 +6,7 @@ import { useNotification } from '@strapi/helper-plugin'; import { Alert } from '@strapi/design-system/Alert'; import { Typography } from '@strapi/design-system/Typography'; -import { getAllConfigDiff } from '../../state/actions/Config'; +import { getAllConfigDiff, getAppEnv } from '../../state/actions/Config'; import ConfigList from '../../components/ConfigList'; import ActionButtons from '../../components/ActionButtons'; @@ -15,14 +15,16 @@ const ConfigPage = () => { const dispatch = useDispatch(); const isLoading = useSelector((state) => state.getIn(['config', 'isLoading'], Map({}))); const configDiff = useSelector((state) => state.getIn(['config', 'configDiff'], Map({}))); + const appEnv = useSelector((state) => state.getIn(['config', 'appEnv'])); useEffect(() => { dispatch(getAllConfigDiff(toggleNotification)); + dispatch(getAppEnv(toggleNotification)); }, []); return ( - {process.env.NODE_ENV === 'production' && ( + {appEnv === 'production' && ( You're in the production environment
diff --git a/admin/src/helpers/configureStore.js b/admin/src/helpers/configureStore.js index 7c250cf..bc77e59 100755 --- a/admin/src/helpers/configureStore.js +++ b/admin/src/helpers/configureStore.js @@ -30,7 +30,7 @@ const configureStore = () => { const composedEnhancers = devtools || compose; const storeEnhancers = composedEnhancers( applyMiddleware(...middlewares), - ...enhancers + ...enhancers, ); const store = createStore( diff --git a/admin/src/helpers/pluginId.js b/admin/src/helpers/pluginId.js index d66b468..4a3a03f 100644 --- a/admin/src/helpers/pluginId.js +++ b/admin/src/helpers/pluginId.js @@ -2,7 +2,7 @@ const pluginPkg = require('../../../package.json'); const pluginId = pluginPkg.name.replace( /^strapi-plugin-/i, - '' + '', ); module.exports = pluginId; diff --git a/admin/src/index.js b/admin/src/index.js index 2359693..50e152e 100644 --- a/admin/src/index.js +++ b/admin/src/index.js @@ -54,7 +54,7 @@ export default { locale, }; }); - }) + }), ); return Promise.resolve(importedTrads); diff --git a/admin/src/state/actions/Config.js b/admin/src/state/actions/Config.js index d27b16a..50d09ac 100644 --- a/admin/src/state/actions/Config.js +++ b/admin/src/state/actions/Config.js @@ -80,3 +80,24 @@ export function setLoadingState(value) { value, }; } + +export function getAppEnv(toggleNotification) { + return async function(dispatch) { + try { + const env = await request('/config-sync/app-env', { + method: 'GET', + }); + dispatch(setAppEnvInState(env)); + } catch (err) { + toggleNotification({ type: 'warning', message: { id: 'notification.error' } }); + } + }; +} + +export const SET_APP_ENV_IN_STATE = 'SET_APP_ENV_IN_STATE'; +export function setAppEnvInState(value) { + return { + type: SET_APP_ENV_IN_STATE, + value, + }; +} diff --git a/admin/src/state/reducers/Config/index.js b/admin/src/state/reducers/Config/index.js index 6b54558..4af6f32 100644 --- a/admin/src/state/reducers/Config/index.js +++ b/admin/src/state/reducers/Config/index.js @@ -5,12 +5,18 @@ */ import { fromJS, Map, List } from 'immutable'; -import { SET_CONFIG_DIFF_IN_STATE, SET_CONFIG_PARTIAL_DIFF_IN_STATE, SET_LOADING_STATE } from '../../actions/Config'; +import { + SET_CONFIG_DIFF_IN_STATE, + SET_CONFIG_PARTIAL_DIFF_IN_STATE, + SET_LOADING_STATE, + SET_APP_ENV_IN_STATE, +} from '../../actions/Config'; const initialState = fromJS({ configDiff: Map({}), partialDiff: List([]), isLoading: false, + appEnv: 'development', }); export default function configReducer(state = initialState, action) { @@ -24,6 +30,9 @@ export default function configReducer(state = initialState, action) { case SET_LOADING_STATE: return state .update('isLoading', () => fromJS(action.value)); + case SET_APP_ENV_IN_STATE: + return state + .update('appEnv', () => fromJS(action.value)); default: return state; } diff --git a/server/controllers/config.js b/server/controllers/config.js index 3390100..d73f416 100644 --- a/server/controllers/config.js +++ b/server/controllers/config.js @@ -83,4 +83,10 @@ module.exports = { return strapi.plugin('config-sync').service('main').getFormattedDiff(); }, + + /** + * Get the current Strapi env. + * @returns {string} The current Strapi environment. + */ + getAppEnv: async () => strapi.server.app.env, }; diff --git a/server/routes/admin.js b/server/routes/admin.js index 68fa6ae..7422b45 100644 --- a/server/routes/admin.js +++ b/server/routes/admin.js @@ -27,5 +27,13 @@ module.exports = { policies: [], }, }, + { + method: "GET", + path: "/app-env", + handler: "config.getAppEnv", + config: { + policies: [], + }, + }, ], }; diff --git a/server/utils/index.js b/server/utils/index.js index c850d89..619c6db 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -15,7 +15,7 @@ const sortByKeys = (unordered) => { obj[key] = unordered[key]; return obj; }, - {} + {}, ); };