diff --git a/Docker/init.sh b/Docker/init.sh index 64b6c1db..5b3438ec 100644 --- a/Docker/init.sh +++ b/Docker/init.sh @@ -84,7 +84,7 @@ elif [ ! -e "./conf.json" ]; then cp conf.sample.json conf.json fi sudo sed -i -e 's/change_this_to_something_very_random__just_anything_other_than_this/'"$cronKey"'/g' conf.json -# node tools/modifyConfiguration.js cpuUsageMarker=CPU subscriptionId=$SUBSCRIPTION_ID thisIsDocker=true pluginKeys="$PLUGIN_KEYS" db="$DATABASE_CONFIG" ssl="$SSL_CONFIG" +node tools/modifyConfiguration.js cpuUsageMarker=CPU subscriptionId=$SUBSCRIPTION_ID thisIsDocker=true pluginKeys="$PLUGIN_KEYS" db="$DATABASE_CONFIG" ssl="$SSL_CONFIG" echo "=============" diff --git a/libs/system/utils.js b/libs/system/utils.js index c41c4f62..4c42f310 100644 --- a/libs/system/utils.js +++ b/libs/system/utils.js @@ -23,26 +23,23 @@ module.exports = (config) => { return response }, getConfiguration: () => { - return new Promise((resolve,reject) => { - fs.readFile(s.location.config,'utf8',function(err,data){ + return new Promise((resolve, reject) => { + const configPath = config.thisIsDocker ? "/config/conf.json" : s.location.config; + + fs.readFile(configPath, 'utf8', (err,data) => { resolve(JSON.parse(data)) - }) - }) + }); + }); }, modifyConfiguration: (postBody) => { - return new Promise((resolve,reject) => { - try{ - if(config.thisIsDocker){ - const dockerConfigFile = '/config/conf.json' - fs.writeFileSync(dockerConfigFile,JSON.stringify(postBody,null,3)) - } - }catch(err){ - console.log(err) - } - fs.writeFile(s.location.config,JSON.stringify(postBody,null,3),function(err){ - resolve(err) - }) - }) + return new Promise((resolve, reject) => { + console.log(s.location.config) + + const configPath = config.thisIsDocker ? "/config/conf.json" : s.location.config; + const configData = JSON.stringify(postBody,null,3); + console.log(postBody) + fs.writeFile(configPath, configData, resolve); + }); }, updateSystem: () => { return new Promise((resolve,reject) => { diff --git a/libs/webServerSuperPaths.js b/libs/webServerSuperPaths.js index 33a29754..ef7292c7 100644 --- a/libs/webServerSuperPaths.js +++ b/libs/webServerSuperPaths.js @@ -250,17 +250,12 @@ module.exports = function(s,config,lang,app){ currentSuperUserList.push(currentSuperUser) } //update master list in system - try{ - if(config.thisIsDocker){ - const dockerSuperFile = '/config/super.json' - fs.writeFileSync(dockerSuperFile,JSON.stringify(currentSuperUserList,null,3)) - } - }catch(err){ - console.log(err) - } - fs.writeFile(s.location.super,JSON.stringify(currentSuperUserList,null,3),function(){ + const configPath = config.thisIsDocker ? "/config/super.json" : s.location.super; + const configData = JSON.stringify(postBody,null,3); + fs.writeFile(configPath, configData, () => { s.tx({f:'save_preferences'},'$') - }) + }); + }else{ endData.ok = false endData.msg = lang.postDataBroken diff --git a/tools/modifyConfiguration.js b/tools/modifyConfiguration.js index e552b742..981fa594 100644 --- a/tools/modifyConfiguration.js +++ b/tools/modifyConfiguration.js @@ -56,16 +56,10 @@ processArgv.forEach(function(val) { console.log(index + ': ' + value); }); -try{ - if(config.thisIsDocker){ - const dockerConfigFile = '/config/conf.json' - fs.writeFileSync(dockerConfigFile,JSON.stringify(config,null,3)) - } -}catch(err){ - console.log(err) -} +const configPath = config.thisIsDocker ? "/config/conf.json" : configLocation; +const configData = JSON.stringify(config,null,3); -fs.writeFile(configLocation,JSON.stringify(config,null,3),function(){ +fs.writeFile(configPath, configData, () =>{ console.log('Changes Complete. Here is what it is now.') console.log(JSON.stringify(config,null,2)) -}) +});