update dependencies, fixes to support new authentication features
[websub-hub] / config / index.js
1 'use strict';
2
3 const common = require('../src/common');
4
5 const defaultEnvironment = 'development';
6 const testEnvironment = 'test';
7
8 /**
9 * Merge environment-specific config objects on top of defaults.
10 * @param {string=} environment from NODE_ENV
11 * @returns {object} config
12 */
13 function Config(environment) {
14 environment = environment || defaultEnvironment;
15 const defaultConfig = require('./default');
16 let envConfig = require(`./${environment}`); // eslint-disable-line security/detect-non-literal-require
17 if (!Array.isArray(envConfig)) {
18 envConfig = Array(envConfig);
19 }
20 // We support arrays of config options in env to allow e.g. resetting an existing array
21 const combinedConfig = common.mergeDeep(defaultConfig, ...envConfig, { environment });
22 if (!environment.includes(testEnvironment)) {
23 /* istanbul ignore next */
24 common.freezeDeep(combinedConfig);
25 }
26 return combinedConfig;
27 }
28
29 module.exports = Config;