2021-10-12 13:43:05 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import Nconf from 'nconf-lite'
|
2015-02-02 09:52:31 +00:00
|
|
|
|
2021-10-12 13:43:05 +00:00
|
|
|
const nconf = new Nconf()
|
2015-02-02 09:52:31 +00:00
|
|
|
|
2016-12-15 22:43:52 +00:00
|
|
|
// Load arguments as highest priority
|
2021-10-12 13:43:05 +00:00
|
|
|
nconf.argv({ lowerCase: true, separator: '__', parseValues: true, useEqualsign: true });
|
2015-02-02 09:52:31 +00:00
|
|
|
|
2016-12-15 22:43:52 +00:00
|
|
|
// Overrides
|
2015-02-02 09:52:31 +00:00
|
|
|
var overrides = {};
|
|
|
|
|
|
|
|
if (nconf.get('prod')) {
|
|
|
|
overrides.NODE_ENV = 'production';
|
2016-12-15 22:43:52 +00:00
|
|
|
} else if (nconf.get('debug')) {
|
2015-02-02 09:52:31 +00:00
|
|
|
overrides.NODE_ENV = 'development';
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:43:52 +00:00
|
|
|
// Load overrides as second priority
|
2015-02-02 09:52:31 +00:00
|
|
|
nconf.overrides(overrides);
|
|
|
|
|
2016-12-15 22:43:52 +00:00
|
|
|
// Load enviroment variables as third priority
|
2015-02-02 09:52:31 +00:00
|
|
|
nconf.env();
|
|
|
|
|
2021-10-12 13:43:05 +00:00
|
|
|
var filename = nconf.get('config') || '../config.json'
|
|
|
|
if (fs.existsSync(filename)) {
|
|
|
|
// Load the config if it exists.
|
|
|
|
nconf.file('main', nconf.get('config') || '../config.json');
|
|
|
|
}
|
2015-02-02 09:52:31 +00:00
|
|
|
|
2016-12-15 22:43:52 +00:00
|
|
|
// Default variables
|
2015-02-02 09:52:31 +00:00
|
|
|
nconf.defaults({
|
|
|
|
name: nconf.get('name') || 'spserver',
|
|
|
|
NODE_ENV: 'development',
|
2016-12-17 01:18:39 +00:00
|
|
|
ip: '0.0.0.0',
|
2015-02-02 09:52:31 +00:00
|
|
|
production: {
|
|
|
|
port: 80,
|
|
|
|
bunyan: {
|
|
|
|
name: nconf.get('name') || 'spserver',
|
2016-12-15 22:52:46 +00:00
|
|
|
stream: 'process.stdout',
|
|
|
|
level: 'info',
|
2015-02-02 09:52:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
development: {
|
|
|
|
port: 3001,
|
|
|
|
bunyan: {
|
|
|
|
name: nconf.get('name') || 'spserver',
|
2016-12-15 22:52:46 +00:00
|
|
|
stream: 'process.stdout',
|
|
|
|
level: 'debug',
|
2015-02-02 09:52:31 +00:00
|
|
|
},
|
2016-12-15 22:52:46 +00:00
|
|
|
},
|
2015-02-02 09:52:31 +00:00
|
|
|
});
|
|
|
|
|
2021-10-12 13:43:05 +00:00
|
|
|
export default nconf
|