2022-02-23 20:25:05 -07:00
|
|
|
'use strict';
|
|
|
|
|
2022-06-09 20:37:07 -06:00
|
|
|
// This file is based off the Gitter config,
|
|
|
|
// https://gitlab.com/gitlab-org/gitter/env/blob/master/lib/config.js
|
2022-02-23 20:25:05 -07:00
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const nconf = require('nconf');
|
2022-08-29 19:33:02 -06:00
|
|
|
const JSON5 = require('json5');
|
2022-02-23 20:25:05 -07:00
|
|
|
|
|
|
|
function configureNodeEnv() {
|
|
|
|
const nodeEnv = process.env.NODE_ENV;
|
|
|
|
if (nodeEnv === 'production') {
|
|
|
|
return 'prod';
|
|
|
|
} else if (nodeEnv === 'development') {
|
|
|
|
return 'dev';
|
|
|
|
}
|
|
|
|
if (nodeEnv) return nodeEnv;
|
|
|
|
|
|
|
|
// Default to NODE_ENV=dev
|
|
|
|
process.env.NODE_ENV = 'dev';
|
|
|
|
return 'dev';
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodeEnv = configureNodeEnv();
|
2022-06-09 19:44:57 -06:00
|
|
|
console.log(`Config is using nodeEnv=${nodeEnv}`);
|
2022-02-23 20:25:05 -07:00
|
|
|
const configDir = path.join(__dirname, '../../config');
|
|
|
|
|
2022-06-09 20:37:07 -06:00
|
|
|
// Setup nconf to use (in-order):
|
|
|
|
// 1. Command-line arguments (argv)
|
|
|
|
// 2. Environment variables (env)
|
|
|
|
// 3. `config/config-{env}.json` files
|
2022-02-23 20:25:05 -07:00
|
|
|
nconf.argv().env('__');
|
|
|
|
|
|
|
|
nconf.add('envUser', {
|
|
|
|
type: 'file',
|
|
|
|
file: path.join(configDir, 'config.' + nodeEnv + '.user-overrides.json'),
|
2022-08-29 19:33:02 -06:00
|
|
|
format: JSON5,
|
2022-02-23 20:25:05 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Only use user-overrides in dev
|
|
|
|
if (nodeEnv === 'dev') {
|
2022-08-29 19:33:02 -06:00
|
|
|
nconf.add('user', {
|
|
|
|
type: 'file',
|
|
|
|
file: path.join(configDir, 'config.user-overrides.json'),
|
|
|
|
format: JSON5,
|
|
|
|
});
|
2022-02-23 20:25:05 -07:00
|
|
|
}
|
|
|
|
|
2022-08-29 19:33:02 -06:00
|
|
|
nconf.add('nodeEnv', {
|
|
|
|
type: 'file',
|
|
|
|
file: path.join(configDir, 'config.' + nodeEnv + '.json'),
|
|
|
|
format: JSON5,
|
|
|
|
});
|
|
|
|
nconf.add('defaults', {
|
|
|
|
type: 'file',
|
|
|
|
file: path.join(configDir, 'config.default.json'),
|
|
|
|
format: JSON5,
|
|
|
|
});
|
2022-02-23 20:25:05 -07:00
|
|
|
|
|
|
|
module.exports = nconf;
|