Merge branch 'v1.3-dev' as v1.3.11
[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 function Config(environment) {
9 environment = environment || defaultEnvironment;
10 const defaultConfig = require('./default');
11 let envConfig = require(`./${environment}`); // eslint-disable-line security/detect-non-literal-require
12 if (!Array.isArray(envConfig)) {
13 envConfig = Array(envConfig);
14 }
15 // We support arrays of config options in env to allow e.g. resetting an existing array
16 const combinedConfig = common.mergeDeep(defaultConfig, ...envConfig, { environment });
17 if (!environment.includes(testEnvironment)) {
18 /* istanbul ignore next */
19 common.freezeDeep(combinedConfig);
20 }
21 return combinedConfig;
22 }
23
24 module.exports = Config;