diff --git a/SettingsHelper.js b/SettingsHelper.js index 951a6657..6f3948bd 100644 --- a/SettingsHelper.js +++ b/SettingsHelper.js @@ -4,6 +4,7 @@ const settings = require('./settings.json'); module.exports = function () { const fields = [ + // Webapp settings { local: 'webroot', env: 'WEB_ROOT', @@ -19,16 +20,6 @@ module.exports = function () { env: 'WEB_ACCESSURL', default: '' }, - { - local: 'serverroot', - env: 'SERVER_ROOT', - default: '' - }, - { - local: 'server_port', - env: 'SERVER_PORT', - default: '8089' - }, { local: 'autoJoin', env: 'AUTOJOIN_ENABLED', @@ -55,9 +46,30 @@ module.exports = function () { default: { mechanism: 'none' } + }, + { + local: 'custom_server', + env: 'CUSTOM_SERVER', + default: '' + }, + { + local: 'servers', + env: 'SERVERS', + default: '' + }, + // Server settings + { + local: 'serverroot', + env: 'SERVER_ROOT', + default: '/slserver' + }, + { + local: 'server_port', + env: 'SERVER_PORT', + default: '8089' } ]; - // Load and export our settings in preference of ENV -> args + // Load and export our settings in preference of Args -> ENV -> Settings file -> Default const output = {}; for (let i = 0; i < fields.length; i++) { const setting = fields[i]; @@ -69,13 +81,20 @@ module.exports = function () { // Remove trailing slashes, if they exist if ((setting.local == 'webroot' || setting.local == 'accessUrl') && output[setting.local].endsWith("/")) { + console.log(`${setting.local}/${setting.env} should not end in '/'. Removing trailing slash(es) for you.`); output[setting.local] = output[setting.local].replace(/\/+$/, ""); } // Add leading slash, if not provided - if (setting.local == 'webroot' && !output[setting.local].startsWith("/")) { + if (setting.local == 'webroot' && output[setting.local].length > 1 && !output[setting.local].startsWith("/")) { + console.log(`${setting.local}/${setting.env} should always start with '/'. Adding the leading slash for you.`); // Make sure it starts with one leading slash output[setting.local] = `/${output[setting.local]}`; } + // Make sure 'webroot' and 'serverroot' aren't set to '/'. Revert to default if they do. + if ((setting.local == 'webroot' || setting.local == 'serverroot') && output[setting.local] == '/') { + console.log(`${setting.local}/${setting.env} cannot be set to '/'. Reverting to default: '${setting.default}'`); + output[setting.local] = setting.default; + } process.env[setting.local] = output[setting.local]; } //console.log('Our settings are', output)