From c8b314b3e39c4d68407440a90c703709e433750b Mon Sep 17 00:00:00 2001 From: Stuart Colville Date: Fri, 6 May 2016 20:10:16 +0100 Subject: [PATCH] Eliminate deferred config values --- config/default.js | 29 +++++++++++++++++------------ config/dev.js | 26 ++++++++++++++++++++++++-- config/development.js | 34 +++++++++++++++++++++++++--------- config/stage.js | 26 ++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 25 deletions(-) diff --git a/config/default.js b/config/default.js index a13437c5fa8..cd7155df27c 100644 --- a/config/default.js +++ b/config/default.js @@ -3,7 +3,6 @@ // live here. const path = require('path'); -const defer = require('config/defer').deferConfig; const appName = process.env.NODE_APP_INSTANCE || null; const validAppNames = [ @@ -16,6 +15,12 @@ if (appName && validAppNames.indexOf(appName) === -1) { throw new Error(`App ${appName} is not enabled`); } +const amoCDN = 'https://addons.cdn.mozilla.net'; +const apiHost = 'https://addons.mozilla.org'; +const apiBase = `${apiHost}/api/v3`; +const startLoginUrl = `${apiBase}/internal/accounts/login/start/`; + + module.exports = { appName, basePath: path.resolve(__dirname, '../'), @@ -35,12 +40,10 @@ module.exports = { serverPort: 4000, // The CDN host for AMO. - amoCDN: 'https://addons.cdn.mozilla.net', - - apiHost: 'https://addons.mozilla.org', - apiPath: '/api/v3', - apiBase: defer((cfg) => cfg.apiHost + cfg.apiPath), - startLoginUrl: defer((cfg) => `${cfg.apiBase}/internal/accounts/login/start/`), + amoCDN, + apiHost, + apiBase, + startLoginUrl, // The keys listed here will be exposed on the client. // Since by definition client-side code is public these config keys @@ -58,11 +61,14 @@ module.exports = { CSP: { directives: { defaultSrc: ["'self'"], - connectSrc: defer((cfg) => ["'self'", cfg.apiHost]), - imgSrc: defer((cfg) => [ + connectSrc: [ "'self'", - cfg.amoCDN, - ]), + apiHost, + ], + imgSrc: [ + "'self'", + amoCDN, + ], scriptSrc: ["'self'"], styleSrc: ["'self'"], reportUri: '/__cspreport__', @@ -78,5 +84,4 @@ module.exports = { // Set to true if you want to disable CSP on Android where it can be buggy. disableAndroid: false, }, - }; diff --git a/config/dev.js b/config/dev.js index cb733dd221f..15e41224a71 100644 --- a/config/dev.js +++ b/config/dev.js @@ -1,6 +1,28 @@ // Config for the -dev server. +const amoCDN = 'https://addons-dev-cdn.allizom.org'; +const apiHost = 'https://addons-dev.allizom.org'; +const apiBase = `${apiHost}/api/v3`; +const startLoginUrl = `${apiBase}/internal/accounts/login/start/`; + + module.exports = { - apiHost: 'https://addons-dev.allizom.org', - amoCDN: 'https://addons-dev-cdn.allizom.org', + apiHost, + apiBase, + amoCDN, + startLoginUrl, + + // Content security policy. + CSP: { + directives: { + connectSrc: [ + "'self'", + apiHost, + ], + imgSrc: [ + "'self'", + amoCDN, + ], + }, + }, }; diff --git a/config/development.js b/config/development.js index 03985babdb0..b36af002a47 100644 --- a/config/development.js +++ b/config/development.js @@ -1,24 +1,40 @@ // Config specific to local development -const defer = require('config/defer').deferConfig; +const webpackServerHost = '127.0.0.1'; +const webpackServerPort = 3001; +const webpackHost = `${webpackServerHost}:${webpackServerPort}`; +const apiHost = 'https://addons-dev.allizom.org'; +const amoCDN = 'https://addons-dev-cdn.allizom.org'; +const apiBase = `${apiHost}/api/v3`; +const startLoginUrl = `${apiBase}/internal/accounts/login/start/`; + module.exports = { - serverPort: 3000, - apiHost: 'https://addons-dev.allizom.org', - amoCDN: 'https://addons-dev-cdn.allizom.org', + apiHost, + amoCDN, isDeployed: false, isDevelopment: true, - webpackServerHost: '127.0.0.1', - webpackServerPort: 3001, - webpackHost: defer((cfg) => `http://${cfg.webpackServerHost}:${cfg.webpackServerPort}`), + serverPort: 3000, + startLoginUrl, + webpackServerHost, + webpackServerPort, + webpackHost, CSP: { directives: { - connectSrc: defer((cfg) => ["'self'", cfg.apiHost, cfg.webpackHost]), - scriptSrc: defer((cfg) => ["'self'", cfg.webpackHost]), + connectSrc: [ + "'self'", + amoCDN, + webpackHost, + ], + scriptSrc: [ + "'self'", + amoCDN, + webpackHost, + ], styleSrc: ["'self'", 'blob:'], }, reportOnly: true, diff --git a/config/stage.js b/config/stage.js index 3b7fbfc9ac6..1dd5eecfc41 100644 --- a/config/stage.js +++ b/config/stage.js @@ -1,6 +1,28 @@ // Config for the stage server. +const amoCDN = 'https://addons-stage-cdn.allizom.org'; +const apiHost = 'https://addons.allizom.org'; +const apiBase = `${apiHost}/api/v3`; +const startLoginUrl = `${apiBase}/internal/accounts/login/start/`; + + module.exports = { - apiHost: 'https://addons.allizom.org', - amoCDN: 'https://addons-stage-cdn.allizom.org', + apiHost, + apiBase, + amoCDN, + startLoginUrl, + + // Content security policy. + CSP: { + directives: { + connectSrc: [ + "'self'", + apiHost, + ], + imgSrc: [ + "'self'", + amoCDN, + ], + }, + }, };