-
Notifications
You must be signed in to change notification settings - Fork 400
Refactor configuration for server and client #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// CONFIG defaults (aka PRODUCTION) | ||
// WARNING: No test/stage/dev/development config should | ||
// live here. | ||
|
||
/* eslint-disable object-shorthand */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not supported here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll need to check - karma pulls this in and that's pure node - not sure if that's using babel. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I set it up with object shorthands and karma still seems to work. |
||
|
||
const path = require('path'); | ||
const defer = require('config/defer').deferConfig; | ||
|
||
const appName = process.env.NODE_APP_INSTANCE || null; | ||
const validAppNames = [ | ||
'disco', | ||
'search', | ||
]; | ||
|
||
// Throw if the appName supplied is not valid. | ||
if (appName && validAppNames.indexOf(appName) === -1) { | ||
throw new Error(`App ${appName} is not enabled`); | ||
} | ||
|
||
module.exports = { | ||
appName: appName, | ||
basePath: path.resolve(__dirname, '../'), | ||
|
||
// 2592000 is 30 days in seconds. | ||
cookieMaxAge: 2592000, | ||
cookieName: 'jwt_api_auth_token', | ||
|
||
// The canonical list of enabled apps. | ||
validAppNames: validAppNames, | ||
|
||
// The node server host and port. | ||
serverHost: '127.0.0.1', | ||
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/`), | ||
|
||
// The keys listed here will be exposed on the client. | ||
// Since by definition client-side code is public these config keys | ||
// must not contain sensitive data. | ||
clientConfigKeys: [ | ||
'apiBase', | ||
'cookieName', | ||
'cookieMaxAge', | ||
'startLoginUrl', | ||
], | ||
|
||
// Content security policy. | ||
CSP: { | ||
directives: { | ||
defaultSrc: ["'self'"], | ||
connectSrc: defer((cfg) => ["'self'", cfg.apiHost]), | ||
imgSrc: defer((cfg) => [ | ||
"'self'", | ||
cfg.amoCDN, | ||
]), | ||
scriptSrc: ["'self'"], | ||
styleSrc: ["'self'"], | ||
reportUri: '/__cspreport__', | ||
}, | ||
|
||
// Set to true if you only want browsers to report errors, not block them | ||
reportOnly: false, | ||
|
||
// Set to true if you want to blindly set all headers: Content-Security-Policy, | ||
// X-WebKit-CSP, and X-Content-Security-Policy. | ||
setAllHeaders: false, | ||
|
||
// Set to true if you want to disable CSP on Android where it can be buggy. | ||
disableAndroid: false, | ||
}, | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Config for the -dev server. | ||
|
||
module.exports = { | ||
apiHost: 'https://addons-dev.allizom.org', | ||
amoCDN: 'https://addons-dev-cdn.allizom.org', | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Config specific to local development | ||
|
||
const defer = require('config/defer').deferConfig; | ||
|
||
module.exports = { | ||
serverPort: 3000, | ||
|
||
apiHost: 'https://addons-dev.allizom.org', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this to: apiHost: process.env.API_HOST || 'https://addons-dev.allizom.org', There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that needs to be done differently to use the proper node-config way. I'll update #298. |
||
amoCDN: 'https://addons-dev-cdn.allizom.org', | ||
|
||
webpackServerHost: '127.0.0.1', | ||
webpackServerPort: 3001, | ||
webpackHost: defer((cfg) => `http://${cfg.webpackServerHost}:${cfg.webpackServerPort}`), | ||
|
||
CSP: { | ||
directives: { | ||
connectSrc: defer((cfg) => ["'self'", cfg.apiHost, cfg.webpackHost]), | ||
scriptSrc: defer((cfg) => ["'self'", cfg.webpackHost]), | ||
styleSrc: ["'self'", 'blob:'], | ||
}, | ||
reportOnly: true, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// The default conf should cover this. | ||
module.exports = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Config for the stage server. | ||
|
||
module.exports = { | ||
apiHost: 'https://addons.allizom.org', | ||
amoCDN: 'https://addons-stage-cdn.allizom.org', | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* This module is a stand-in for the config module | ||
* when imported on the client. | ||
* When webpack builds the client-side code it exposes | ||
* the clientConfig config via the definePlugin as CLIENT_CONFIG. | ||
*/ | ||
|
||
const clientConfig = new Map(); | ||
|
||
Object.keys(CLIENT_CONFIG).forEach((key) => { | ||
clientConfig.set(key, CLIENT_CONFIG[key]); | ||
}); | ||
|
||
module.exports = clientConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On other projects we've made development the default. I guess since this is still no-configuration-needed for development having production default is cool?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I feel it's a better way around to have production config happen if you don't override something than to have development config if you don't override something.