From d5a9eacef0165fb4a82270f3e6837a91773e7d4c Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 17 Apr 2019 13:48:39 +0200 Subject: [PATCH] standardize loading of server configuration --- lib/load-config.js | 12 ++++++++++++ scripts/check-account-deletion.js | 2 +- scripts/check-accounts.js | 2 +- scripts/delete-inactive.js | 7 +------ scripts/expire-channels.js | 2 +- scripts/load-config.js | 7 ------- scripts/pinned.js | 2 +- server.js | 12 +----------- 8 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 lib/load-config.js delete mode 100644 scripts/load-config.js diff --git a/lib/load-config.js b/lib/load-config.js new file mode 100644 index 000000000..7b9f73251 --- /dev/null +++ b/lib/load-config.js @@ -0,0 +1,12 @@ +var config; +try { + config = require("../config/config"); + if (config.adminEmail === 'i.did.not.read.my.config@cryptpad.fr') { + console.log("You can configure the administrator email (adminEmail) in your config/config.js file"); + } +} catch (e) { + console.log("You can customize the configuration by copying config/config.example.js to config/config.js"); + config = require("../config/config.example"); +} +module.exports = config; + diff --git a/scripts/check-account-deletion.js b/scripts/check-account-deletion.js index 459fad4e9..69d720cb5 100644 --- a/scripts/check-account-deletion.js +++ b/scripts/check-account-deletion.js @@ -4,7 +4,7 @@ const nThen = require('nthen'); const Pinned = require('./pinned'); const Nacl = require('tweetnacl'); const Path = require('path'); -const Config = require('./load-config'); +const Config = require('../lib/load-config'); const hashesFromPinFile = (pinFile, fileName) => { var pins = {}; diff --git a/scripts/check-accounts.js b/scripts/check-accounts.js index 604e9d224..4d0067d43 100644 --- a/scripts/check-accounts.js +++ b/scripts/check-accounts.js @@ -1,6 +1,6 @@ /* globals Buffer */ var Https = require('https'); -var Config = require("../config/config.js"); +var Config = require("../lib/load-config"); var Package = require("../package.json"); var body = JSON.stringify({ diff --git a/scripts/delete-inactive.js b/scripts/delete-inactive.js index bf64509ed..9dbfb0707 100644 --- a/scripts/delete-inactive.js +++ b/scripts/delete-inactive.js @@ -3,12 +3,7 @@ const Fs = require("fs"); const nThen = require("nthen"); const Saferphore = require("saferphore"); const PinnedData = require('./pinneddata'); -let config; -try { - config = require('./config/config'); -} catch (e) { - config = require('./config/config.example'); -} +const config = require("../lib/load-config"); if (!config.inactiveTime || typeof(config.inactiveTime) !== "number") { return; } diff --git a/scripts/expire-channels.js b/scripts/expire-channels.js index 38e0c10c1..5c87c7cea 100644 --- a/scripts/expire-channels.js +++ b/scripts/expire-channels.js @@ -3,7 +3,7 @@ var Path = require("path"); var nThen = require("nthen"); -var config = require("./load-config"); +var config = require("../lib/load-config"); var FileStorage = require('../' + config.storage || './storage/file'); var root = Path.resolve('../' + config.taskPath || './tasks'); diff --git a/scripts/load-config.js b/scripts/load-config.js deleted file mode 100644 index d32f9d31e..000000000 --- a/scripts/load-config.js +++ /dev/null @@ -1,7 +0,0 @@ -var config; -try { - config = require("../config/config"); -} catch (e) { - config = require("../config/config.example"); -} -module.exports = config; diff --git a/scripts/pinned.js b/scripts/pinned.js index 2c00310a4..ba1054d77 100644 --- a/scripts/pinned.js +++ b/scripts/pinned.js @@ -106,6 +106,6 @@ if (!module.parent) { console.log(x + ' ' + JSON.stringify(data[x])); }); }, { - pinPath: require("../config/config").pinPath + pinPath: require("../lib/load-config").pinPath }); } diff --git a/server.js b/server.js index 24d7fecc3..7d64195c3 100644 --- a/server.js +++ b/server.js @@ -11,17 +11,7 @@ var Package = require('./package.json'); var Path = require("path"); var nThen = require("nthen"); -var config; -try { - config = require('./config/config'); -} catch (e) { - console.log("You can customize the configuration by copying config/config.example.js to config/config.js"); - config = require('./config/config.example'); -} - -if (config.adminEmail === 'i.did.not.read.my.config@cryptpad.fr') { - console.log("You can configure the administrator email (adminEmail) in your config/config.js file"); -} +var config = require("./lib/load-config"); var websocketPort = config.websocketPort || config.httpPort; var useSecureWebsockets = config.useSecureWebsockets || false;