From 200cd66d66d9cdd10ad1ea1a1a0acde79050c093 Mon Sep 17 00:00:00 2001 From: MathWhiz Date: Mon, 27 Nov 2017 20:38:27 -0600 Subject: [PATCH] Use config when starting development server (#9410) * Use config when starting development server * import nconf setup from website * Add comment explaining choice * Fix lint issues --- webpack/config/index.js | 20 ++++++++++++++------ webpack/config/prod.env.js | 10 ++-------- website/server/libs/setupNconf.js | 5 +++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/webpack/config/index.js b/webpack/config/index.js index 4a05a1d9dc..ff54852be9 100644 --- a/webpack/config/index.js +++ b/webpack/config/index.js @@ -3,6 +3,14 @@ const path = require('path'); const staticAssetsDirectory = './website/static/.'; // The folder where static files (not processed) live const prodEnv = require('./prod.env'); const devEnv = require('./dev.env'); +const nconf = require('nconf'); +const setupNconf = require('../../website/server/libs/setupNconf'); + +let configFile = path.join(path.resolve(__dirname, '../../config.json')); + +setupNconf(configFile); + +const DEV_BASE_URL = nconf.get('BASE_URL'); module.exports = { build: { @@ -33,25 +41,25 @@ module.exports = { assetsPublicPath: '/', staticAssetsDirectory, proxyTable: { - // proxy all requests starting with /api/v3 to localhost:3000 + // proxy all requests starting with /api/v3 to IP:PORT as specified in the top-level config '/api/v3': { - target: 'http://localhost:3000', + target: DEV_BASE_URL, changeOrigin: true, }, '/stripe': { - target: 'http://localhost:3000', + target: DEV_BASE_URL, changeOrigin: true, }, '/amazon': { - target: 'http://localhost:3000', + target: DEV_BASE_URL, changeOrigin: true, }, '/paypal': { - target: 'http://localhost:3000', + target: DEV_BASE_URL, changeOrigin: true, }, '/logout': { - target: 'http://localhost:3000', + target: DEV_BASE_URL, changeOrigin: true, }, }, diff --git a/webpack/config/prod.env.js b/webpack/config/prod.env.js index ea7ffdd0be..079252b8b8 100644 --- a/webpack/config/prod.env.js +++ b/webpack/config/prod.env.js @@ -1,17 +1,11 @@ const nconf = require('nconf'); const { join, resolve } = require('path'); +const setupNconf = require('../../website/server/libs/setupNconf'); const PATH_TO_CONFIG = join(resolve(__dirname, '../../config.json')); let configFile = PATH_TO_CONFIG; -nconf - .argv() - .env() - .file('user', configFile); - -nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production'); -nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development'); -nconf.set('IS_TEST', nconf.get('NODE_ENV') === 'test'); +setupNconf(configFile); // @TODO: Check if we can import from client. Items like admin emails can be imported // and that should be prefered diff --git a/website/server/libs/setupNconf.js b/website/server/libs/setupNconf.js index 51c643cd20..3a34681729 100644 --- a/website/server/libs/setupNconf.js +++ b/website/server/libs/setupNconf.js @@ -1,5 +1,6 @@ -import nconf from 'nconf'; -import { join, resolve } from 'path'; +// require allows import from webpack +const nconf = require('nconf'); +const { join, resolve } = require('path'); const PATH_TO_CONFIG = join(resolve(__dirname, '../../../config.json'));