Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function reloadConfig() {
var newconfig;
nconf.remove('conf');
nconf.add('conf', {type:'file', file: './worker-config.json'});
newconfig = nconf.get('osync');
var refreshTime = config.configRefresh;
var vistaSitesChanged = false;
// console.log('refreshing config');
//if file refresh changed, redo the file polling
if(newconfig.configRefresh !== config.configRefresh) {
clearInterval(reloadTimer);
reloadTimer = setInterval(reloadConfig, newconfig.configRefresh);
}
if( JSON.stringify(newconfig.vistaSites) !== JSON.stringify(config.vistaSites) ) {
vistaSitesChanged = true;
}
//update configuration with new settings
var newConfigString = JSON.stringify(newconfig);
if(cachedConfig !== newConfigString) {
Config.prototype.init = function() {
nconf.file('local', file.configFile())
.add('global', {type: 'literal', store: DEFAULT_CONFIG})
.defaults({});
const cfg = nconf.get();
nconf.remove('local');
nconf.remove('global');
// HACK: remove old style configs
for (let x in cfg) {
if (x === x.toUpperCase()) delete cfg[x];
}
delete DEFAULT_CONFIG.type;
delete cfg.type;
_.extendOwn(this, cfg);
};
// check if we just created the folder,
// if there's no config yet,
// or if the savers folder was empty
if ( made === true || ! fs.existsSync(configPath) || fs.readdirSync(saversDir).length === 0 ) {
_firstLoad = true;
results.first = true;
}
try {
nconf.remove("file").file({
file: configPath
});
}
catch(e) {
fs.unlinkSync(configPath);
nconf.remove("file").file({
file: configPath
});
}
ensureDefaults();
if ( _firstLoad === true ) {
writeSync();
}
else if ( typeof(load_savers) === "undefined" || load_savers === true ) {
results.setup = true;
}
resolve(results);
});
});
Config.prototype.init = function() {
nconf.file('local', file.configFile())
.add('global', {type: 'literal', store: DEFAULT_CONFIG})
.defaults({});
const cfg = nconf.get();
nconf.remove('local');
nconf.remove('global');
// HACK: remove old style configs
for (let x in cfg) {
if (x === x.toUpperCase()) delete cfg[x];
}
delete DEFAULT_CONFIG.type;
delete cfg.type;
_.extendOwn(this, cfg);
};
afterEach(function () {
nconf.remove(key);
});
Loader.restart = function () {
killWorkers();
nconf.remove('file');
nconf.use('file', { file: pathToConfig });
fs.readFile(pathToConfig, { encoding: 'utf-8' }, function (err, configFile) {
if (err) {
console.error('Error reading config');
throw err;
}
var conf = JSON.parse(configFile);
nconf.stores.env.readOnly = false;
nconf.set('url', conf.url);
nconf.stores.env.readOnly = true;
if (process.env.url !== conf.url) {
process.env.url = conf.url;
var remove = function (key) {
nconf.remove(key);
};