spserver/lib/config.mjs

59 lines
1.4 KiB
JavaScript
Raw Normal View History

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import Nconf from 'nconf-lite'
2015-02-02 09:52:31 +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
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();
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
const __dirname = path.dirname(fileURLToPath(import.meta.url))
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',
stream: 'process.stdout',
level: 'info',
2015-02-02 09:52:31 +00:00
},
},
sslkey: path.resolve(path.join(__dirname, '../key.pem')),
sslcert: path.resolve(path.join(__dirname, '../cert.pem')),
2015-02-02 09:52:31 +00:00
development: {
port: 3001,
bunyan: {
name: nconf.get('name') || 'spserver',
stream: 'process.stdout',
level: 'debug',
2015-02-02 09:52:31 +00:00
},
},
2015-02-02 09:52:31 +00:00
});
export default nconf