2018-07-20 04:31:44 +00:00
|
|
|
|
2019-04-20 08:03:44 +00:00
|
|
|
const args = require('args-parser')(process.argv);
|
2020-03-11 15:45:10 +00:00
|
|
|
const settings = require('./settings.json');
|
2019-04-20 08:03:44 +00:00
|
|
|
|
2018-07-20 04:31:44 +00:00
|
|
|
module.exports = function () {
|
|
|
|
const fields = [
|
2020-03-14 06:04:59 +00:00
|
|
|
// Webapp settings
|
2020-03-04 04:12:44 +00:00
|
|
|
{
|
|
|
|
local: 'webroot',
|
|
|
|
env: 'WEB_ROOT',
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'webapp_port',
|
|
|
|
env: 'WEB_PORT',
|
|
|
|
default: '8088'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'accessUrl',
|
|
|
|
env: 'WEB_ACCESSURL',
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'autoJoin',
|
|
|
|
env: 'AUTOJOIN_ENABLED',
|
|
|
|
default: 'false'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'autoJoinServer',
|
|
|
|
env: 'AUTOJOIN_SERVERURL',
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'autoJoinRoom',
|
|
|
|
env: 'AUTOJOIN_ROOM',
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'autoJoinPassword',
|
|
|
|
env: 'AUTOJOIN_PASSWORD',
|
|
|
|
default: ''
|
2020-03-14 05:53:48 +00:00
|
|
|
},
|
2020-03-14 06:10:50 +00:00
|
|
|
{
|
|
|
|
local: 'authentication',
|
|
|
|
env: 'AUTHENTICATION',
|
|
|
|
default: {
|
|
|
|
mechanism: 'none'
|
|
|
|
}
|
|
|
|
},
|
2020-03-14 05:53:48 +00:00
|
|
|
{
|
2020-03-21 20:32:40 +00:00
|
|
|
local: 'customServer',
|
2020-03-14 05:53:48 +00:00
|
|
|
env: 'CUSTOM_SERVER',
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'servers',
|
|
|
|
env: 'SERVERS',
|
|
|
|
default: ''
|
2020-03-14 06:04:59 +00:00
|
|
|
},
|
|
|
|
// Server settings
|
|
|
|
{
|
|
|
|
local: 'serverroot',
|
|
|
|
env: 'SERVER_ROOT',
|
|
|
|
default: '/slserver'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
local: 'server_port',
|
|
|
|
env: 'SERVER_PORT',
|
|
|
|
default: '8089'
|
2020-03-04 04:12:44 +00:00
|
|
|
}
|
2019-04-20 08:03:44 +00:00
|
|
|
];
|
2020-03-14 05:53:48 +00:00
|
|
|
// Load and export our settings in preference of Args -> ENV -> Settings file -> Default
|
2019-04-20 08:03:44 +00:00
|
|
|
const output = {};
|
2018-07-20 04:31:44 +00:00
|
|
|
for (let i = 0; i < fields.length; i++) {
|
2019-04-20 08:03:44 +00:00
|
|
|
const setting = fields[i];
|
2020-03-04 04:12:44 +00:00
|
|
|
// console.log('Processing setting', setting);
|
|
|
|
// console.log(`Args: '${args[setting.env]}'; '${args[setting.local]}'`);
|
|
|
|
// console.log(`ENV: '${process.env[setting.env]}'; '${process.env[setting.local]}'`);
|
|
|
|
// console.log(`Settings: '${settings[setting.local]}'; '${setting.default}'`);
|
2020-03-24 16:47:36 +00:00
|
|
|
output[setting.local] = args[setting.env] || args[setting.local] || process.env[setting.env] || process.env[setting.local] || settings[setting.env] || settings[setting.local] || setting.default;
|
2020-03-04 04:12:44 +00:00
|
|
|
|
2020-03-24 17:08:02 +00:00
|
|
|
// Backwards compatibilty for PORT ENV setting
|
|
|
|
if(setting.local == 'webapp_port' && output[setting.local] == 8088) {
|
|
|
|
let port = args['PORT'] || process.env['PORT'] || settings['PORT'];
|
2020-03-24 17:41:28 +00:00
|
|
|
if(port && port !== 8088) {
|
2020-03-24 17:08:02 +00:00
|
|
|
console.log(`Please change 'PORT' to 'WEB_PORT'. Setting WEB_PORT to '${port}'`)
|
|
|
|
output[setting.local] = port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 04:12:44 +00:00
|
|
|
// Remove trailing slashes, if they exist
|
|
|
|
if ((setting.local == 'webroot' || setting.local == 'accessUrl') && output[setting.local].endsWith("/")) {
|
2020-03-14 05:53:48 +00:00
|
|
|
console.log(`${setting.local}/${setting.env} should not end in '/'. Removing trailing slash(es) for you.`);
|
2020-03-04 04:12:44 +00:00
|
|
|
output[setting.local] = output[setting.local].replace(/\/+$/, "");
|
|
|
|
}
|
|
|
|
// Add leading slash, if not provided
|
2020-03-15 05:02:33 +00:00
|
|
|
if (setting.local == 'webroot' && output[setting.local].length > 1 && !output[setting.local].startsWith("/")) {
|
2020-03-14 05:53:48 +00:00
|
|
|
console.log(`${setting.local}/${setting.env} should always start with '/'. Adding the leading slash for you.`);
|
2020-03-04 04:12:44 +00:00
|
|
|
// Make sure it starts with one leading slash
|
|
|
|
output[setting.local] = `/${output[setting.local]}`;
|
|
|
|
}
|
2020-03-14 05:53:48 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2020-03-24 16:48:10 +00:00
|
|
|
process.env[setting.env] = output[setting.local];
|
2018-07-20 04:31:44 +00:00
|
|
|
}
|
2020-03-04 04:12:44 +00:00
|
|
|
//console.log('Our settings are', output)
|
2019-04-20 08:03:44 +00:00
|
|
|
return output;
|
|
|
|
};
|