2017-06-22 01:04:19 +00:00
|
|
|
const path = require('path');
|
|
|
|
|
2018-01-13 00:14:45 +00:00
|
|
|
const electronIsDev = require('electron-is-dev');
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2018-01-30 00:57:49 +00:00
|
|
|
let environment;
|
|
|
|
|
|
|
|
// In production mode, NODE_ENV cannot be customized by the user
|
|
|
|
if (electronIsDev) {
|
|
|
|
environment = process.env.NODE_ENV || 'development';
|
|
|
|
} else {
|
|
|
|
environment = 'production';
|
|
|
|
}
|
2017-06-22 01:04:19 +00:00
|
|
|
|
|
|
|
// Set environment vars to configure node-config before requiring it
|
|
|
|
process.env.NODE_ENV = environment;
|
|
|
|
process.env.NODE_CONFIG_DIR = path.join(__dirname, '..', 'config');
|
|
|
|
|
|
|
|
if (environment === 'production') {
|
|
|
|
// harden production config against the local env
|
|
|
|
process.env.NODE_CONFIG = '';
|
|
|
|
process.env.NODE_CONFIG_STRICT_MODE = true;
|
|
|
|
process.env.HOSTNAME = '';
|
|
|
|
process.env.NODE_APP_INSTANCE = '';
|
|
|
|
process.env.ALLOW_CONFIG_MUTATIONS = '';
|
|
|
|
process.env.SUPPRESS_NO_CONFIG_WARNING = '';
|
2019-04-16 00:12:57 +00:00
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '';
|
2017-06-22 01:04:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 00:14:45 +00:00
|
|
|
// We load config after we've made our modifications to NODE_ENV
|
|
|
|
const config = require('config');
|
|
|
|
|
|
|
|
config.environment = environment;
|
2017-06-22 01:04:19 +00:00
|
|
|
|
|
|
|
// Log resulting env vars in use by config
|
|
|
|
[
|
|
|
|
'NODE_ENV',
|
|
|
|
'NODE_CONFIG_DIR',
|
|
|
|
'NODE_CONFIG',
|
|
|
|
'ALLOW_CONFIG_MUTATIONS',
|
|
|
|
'HOSTNAME',
|
|
|
|
'NODE_APP_INSTANCE',
|
2018-01-08 21:19:25 +00:00
|
|
|
'SUPPRESS_NO_CONFIG_WARNING',
|
2018-05-02 01:54:43 +00:00
|
|
|
].forEach(s => {
|
2018-01-08 21:19:25 +00:00
|
|
|
console.log(`${s} ${config.util.getEnv(s)}`);
|
2017-06-22 01:04:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = config;
|