Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if config files exist but are blank we write blank files for nconf
if(fs.existsSync(config_app, 'utf8')){
if(fs.readFileSync(config_app, 'utf8') === ''){
fs.writeFileSync(config_app, '{}', 'utf8');
}
}
if(fs.existsSync(config_connections, 'utf8')){
if(fs.readFileSync(config_connections, 'utf8') === ''){
fs.writeFileSync(config_connections, '{}', 'utf8');
}
}
// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});
// set app defaults
var app_host = process.env.HOST || '0.0.0.0';
var app_port = process.env.PORT || 1234;
// get the app configs and override if present
if(nconf.stores.app.get('app:host') !== undefined){
app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') !== undefined){
app_port = nconf.stores.app.get('app:port');
}
if(nconf.stores.app.get('app:locale') !== undefined){
i18n.setLocale(nconf.stores.app.get('app:locale'));
}
nconf = require('nconf');
// Import from process.env and process.argv
nconf.argv().env();
// Import from /private assets
nconf.add('env', { type: 'literal', store: JSON.parse(Assets.getText("settings.env.json"))});
nconf.add('domain', { type: 'literal', store: JSON.parse(Assets.getText("settings.domain.json"))});
nconf.add('labvm', { type: 'literal', store: JSON.parse(Assets.getText("settings.labvm.json"))});
nconf.add('google', { type: 'literal', store: JSON.parse(Assets.getText("settings.google.json"))});
// Set Defaults
// if config files exist but are blank we write blank files for nconf
if(fs.existsSync(config_app, 'utf8')){
if(fs.readFileSync(config_app, 'utf8') === ''){
fs.writeFileSync(config_app, '{}', 'utf8');
}
}
if(fs.existsSync(config_connections, 'utf8')){
if(fs.readFileSync(config_connections, 'utf8') === ''){
fs.writeFileSync(config_connections, '{}', 'utf8');
}
}
// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});
// set app defaults
var app_host = process.env.HOST || 'localhost';
var app_port = process.env.PORT || 1234;
// get the app configs and override if present
if(nconf.stores.app.get('app:host') !== undefined){
app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') !== undefined){
app_port = nconf.stores.app.get('app:port');
}
if(nconf.stores.app.get('app:locale') !== undefined){
i18n.setLocale(nconf.stores.app.get('app:locale'));
}
// if config files exist but are blank we write blank files for nconf
if(fs.existsSync(config_app, 'utf8')){
if(fs.readFileSync(config_app, 'utf8') === ''){
fs.writeFileSync(config_app, '{}', 'utf8');
}
}
if(fs.existsSync(config_connections, 'utf8')){
if(fs.readFileSync(config_connections, 'utf8') === ''){
fs.writeFileSync(config_connections, '{}', 'utf8');
}
}
// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});
// set app defaults
var app_host = process.env.HOST || '0.0.0.0';
var app_port = process.env.PORT || 1234;
// get the app configs and override if present
if(nconf.stores.app.get('app:host') !== undefined){
app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') !== undefined){
app_port = nconf.stores.app.get('app:port');
}
if(nconf.stores.app.get('app:locale') !== undefined){
i18n.setLocale(nconf.stores.app.get('app:locale'));
}
var nconf = require('nconf');
var commentedJson = {
stringify: function (obj, replacer, spacing) {
return JSON.stringify(obj, replacer || null, spacing || 2);
},
parse: function (obj) {
return JSON.parse(removeComments(obj));
}
};
nconf.add('main', {
type: 'file',
format: commentedJson,
file: 'config/config.json'
});
module.exports = nconf.get();
/**
* Thank you for this work by James padolsey who provide 'removeComments' function on the following web site.
*
* http://james.padolsey.com/javascript/javascript-comment-removal-revisted/
*/
function removeComments(str) {
var uid = '_' + +new Date(),
].forEach(function (item) {
nconf.add(item, {
type: 'file',
file: path.resolve(process.cwd(), 'configs', (item + '.json'))
});
});
].forEach(function(item) {
nconf.add(item, {
type: 'file',
file: path.resolve(process.cwd(), 'configs', (item + '.json'))
});
});
['current/app', 'common/app'].forEach(function (item) {
nconf.add(item, {
type: 'file',
file: path.resolve(process.cwd(), 'configs', (item + '.json'))
});
});