From ce07746bee98e98246d8f80637f39e6190788b07 Mon Sep 17 00:00:00 2001 From: Hannu Lyytikainen Date: Thu, 16 Nov 2017 18:31:31 +0200 Subject: [PATCH 1/2] Add runtime environment variable Add a variable that can be used to differentiate between dev, staging and production environments. --- server/index.js | 3 ++- server/log.js | 2 +- src/config.js | 4 ++-- src/store.js | 5 ++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/index.js b/server/index.js index 959bfbe8..1d06a3f8 100644 --- a/server/index.js +++ b/server/index.js @@ -33,7 +33,8 @@ const log = require('./log'); const { sitemapStructure } = require('./sitemap'); const buildPath = path.resolve(__dirname, '..', 'build'); -const dev = process.env.NODE_ENV !== 'production'; +const env = process.env.REACT_APP_ENV; +const dev = env !== 'staging' && env !== 'production'; const PORT = process.env.PORT || 4000; const CLIENT_ID = process.env.REACT_APP_SHARETRIBE_SDK_CLIENT_ID || '08ec69f6-d37e-414d-83eb-324e94afddf0'; diff --git a/server/log.js b/server/log.js index 708c7601..7a5655f0 100644 --- a/server/log.js +++ b/server/log.js @@ -6,7 +6,7 @@ const Raven = require('raven'); -const ENV = process.env.NODE_ENV; +const ENV = process.env.REACT_APP_ENV; const SENTRY_DSN = process.env.SERVER_SENTRY_DSN; /** diff --git a/src/config.js b/src/config.js index 91c57fff..3a7d0300 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1,5 @@ -const env = process.env.NODE_ENV; -const dev = env !== 'production'; +const env = process.env.REACT_APP_ENV; +const dev = env !== 'staging' && env !== 'production'; // To pass environment variables to the client app in the build // script, react-scripts (and the sharetribe-scripts fork of diff --git a/src/store.js b/src/store.js index b667e8f5..85a0e059 100644 --- a/src/store.js +++ b/src/store.js @@ -3,6 +3,7 @@ import { createStore, applyMiddleware, compose } from 'redux'; import thunk from 'redux-thunk'; import createReducer from './reducers'; import * as analytics from './analytics/analytics'; +import config from './config'; /** * Create a new store with the given initial state. Adds Redux @@ -13,9 +14,7 @@ export default function configureStore(initialState = {}, sdk = null, analyticsH // Enable Redux Devtools in client side dev mode. const composeEnhancers = - process.env.NODE_ENV !== 'production' && - typeof window === 'object' && - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ + config.dev && typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose; From 29160d6a45981943ae7b5b0a6ce0c385984231ba Mon Sep 17 00:00:00 2001 From: Hannu Lyytikainen Date: Fri, 17 Nov 2017 14:49:26 +0200 Subject: [PATCH 2/2] Default to production environment --- server/index.js | 4 ++-- src/config.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/index.js b/server/index.js index 1d06a3f8..58bba691 100644 --- a/server/index.js +++ b/server/index.js @@ -33,8 +33,8 @@ const log = require('./log'); const { sitemapStructure } = require('./sitemap'); const buildPath = path.resolve(__dirname, '..', 'build'); -const env = process.env.REACT_APP_ENV; -const dev = env !== 'staging' && env !== 'production'; +const env = process.env.REACT_APP_ENV === undefined ? 'production' : process.env.REACT_APP_ENV; +const dev = process.env.REACT_APP_ENV === 'development'; const PORT = process.env.PORT || 4000; const CLIENT_ID = process.env.REACT_APP_SHARETRIBE_SDK_CLIENT_ID || '08ec69f6-d37e-414d-83eb-324e94afddf0'; diff --git a/src/config.js b/src/config.js index 3a7d0300..856ac32e 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1,5 @@ -const env = process.env.REACT_APP_ENV; -const dev = env !== 'staging' && env !== 'production'; +const env = process.env.REACT_APP_ENV === undefined ? 'production' : process.env.REACT_APP_ENV; +const dev = process.env.REACT_APP_ENV === 'development'; // To pass environment variables to the client app in the build // script, react-scripts (and the sharetribe-scripts fork of