diff --git a/src/config/index.js b/src/config/index.js index 5c1f8de8078..8b4ade862f5 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,68 +1,73 @@ import path from 'path'; const config = new Map(); -const NODE_ENV = process.env.NODE_ENV; - -// Default to production unless overridden. -config.set('env', NODE_ENV || 'production'); - -config.set('basePath', path.resolve(__dirname, '../')); - -// This is the host / port for running as production. -config.set('serverHost', process.env.SERVER_HOST || '127.0.0.1'); -config.set('serverPort', process.env.SERVER_PORT || 4000); - -// This is the host / port for the development instance. -config.set('devServerHost', process.env.SERVER_HOST || '127.0.0.1'); -config.set('devServerPort', process.env.SERVER_PORT || 3000); - -// This is the host / port for the webpack dev server. -config.set('webpackServerHost', process.env.WEBPACK_SERVER_HOST || '127.0.0.1'); -config.set('webpackServerPort', process.env.WEBPACK_SERVER_PORT || 3001); - -config.set('apiHost', - process.env.API_HOST || - NODE_ENV === 'development' ? - 'https://addons-dev.allizom.org' : 'https://addons.mozilla.org'); - -config.set('apiPath', process.env.API_PATH || '/api/v3'); -config.set('apiBase', config.get('apiHost') + config.get('apiPath')); - -const CSP = { - directives: { - connectSrc: ["'self'", config.get('apiHost')], - defaultSrc: ["'self'"], - 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, -}; -const WEBPACK_HOST = - `http://${config.get('webpackServerHost')}:${config.get('webpackServerPort')}`; - -if (config.get('env') === 'development') { - CSP.directives.scriptSrc.push(WEBPACK_HOST); - CSP.directives.styleSrc.push('blob:'); - CSP.directives.connectSrc.push(WEBPACK_HOST); - CSP.reportOnly = true; -} - -config.set('CSP', CSP); - -const APP_NAMES = ['search', 'disco']; -if (APP_NAMES.indexOf(process.env.APP_NAME) < 0) { - config.set('currentApp', 'core'); -} else { - config.set('currentApp', process.env.APP_NAME); -} + +/* istanbul ignore next */ +// Looks like you can't ignore a file but you can ignore a function, we don't want coverage here. +(function defineConfig() { + const NODE_ENV = process.env.NODE_ENV; + + // Default to production unless overridden. + config.set('env', NODE_ENV || 'production'); + + config.set('basePath', path.resolve(__dirname, '../')); + + // This is the host / port for running as production. + config.set('serverHost', process.env.SERVER_HOST || '127.0.0.1'); + config.set('serverPort', process.env.SERVER_PORT || 4000); + + // This is the host / port for the development instance. + config.set('devServerHost', process.env.SERVER_HOST || '127.0.0.1'); + config.set('devServerPort', process.env.SERVER_PORT || 3000); + + // This is the host / port for the webpack dev server. + config.set('webpackServerHost', process.env.WEBPACK_SERVER_HOST || '127.0.0.1'); + config.set('webpackServerPort', process.env.WEBPACK_SERVER_PORT || 3001); + + config.set('apiHost', + process.env.API_HOST || + NODE_ENV === 'development' ? + 'https://addons-dev.allizom.org' : 'https://addons.mozilla.org'); + + config.set('apiPath', process.env.API_PATH || '/api/v3'); + config.set('apiBase', config.get('apiHost') + config.get('apiPath')); + + const CSP = { + directives: { + connectSrc: ["'self'", config.get('apiHost')], + defaultSrc: ["'self'"], + 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, + }; + const WEBPACK_HOST = + `http://${config.get('webpackServerHost')}:${config.get('webpackServerPort')}`; + + if (config.get('env') === 'development') { + CSP.directives.scriptSrc.push(WEBPACK_HOST); + CSP.directives.styleSrc.push('blob:'); + CSP.directives.connectSrc.push(WEBPACK_HOST); + CSP.reportOnly = true; + } + + config.set('CSP', CSP); + + const APP_NAMES = ['search', 'disco']; + if (APP_NAMES.indexOf(process.env.APP_NAME) < 0) { + config.set('currentApp', 'core'); + } else { + config.set('currentApp', process.env.APP_NAME); + } +}()); export default config; diff --git a/src/core/api/index.js b/src/core/api/index.js index ff85a86f100..1b3b1d43746 100644 --- a/src/core/api/index.js +++ b/src/core/api/index.js @@ -14,13 +14,9 @@ function makeQueryString(opts) { return Object.keys(opts).map((k) => `${k}=${opts[k]}`).join('&'); } -function callApi(endpoint, schema, params = {}) { +function callApi(endpoint, schema, params) { const queryString = makeQueryString(params); - let fullUrl = `${API_BASE}/${endpoint}/`; - if (queryString) { - fullUrl += `?${queryString}`; - } - return fetch(fullUrl) + return fetch(`${API_BASE}/${endpoint}/?${queryString}`) .then((response) => response.json()) .then((response) => normalize(response, schema)); } diff --git a/src/core/containers/App.js b/src/core/containers/App.js index 839218b6961..0b9cde279e2 100644 --- a/src/core/containers/App.js +++ b/src/core/containers/App.js @@ -4,7 +4,7 @@ import { Link } from 'react-router'; export default class App extends React.Component { render() { return ( -