chore: take same config options from env and override
port, listen ip, session name, session secret
This commit is contained in:
parent
f36af08d36
commit
c7851da84a
1 changed files with 11 additions and 0 deletions
|
@ -83,6 +83,14 @@ let config = {
|
||||||
safeShutdownDuration: 300,
|
safeShutdownDuration: 300,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We want our environment varaibles to take priority if they're set
|
||||||
|
function setOverrides() {
|
||||||
|
config.listen.ip = process.env.LISTEN_IP || config.listen.ip;
|
||||||
|
config.listen.port = process.env.PORT || config.listen.port;
|
||||||
|
config.session.name = process.env.SESSION_NAME || config.session.name;
|
||||||
|
config.session.secret = process.env.SESSION_SECRET || config.session.secret;
|
||||||
|
}
|
||||||
|
|
||||||
// test if config.json exists, if not provide error message but try to run anyway
|
// test if config.json exists, if not provide error message but try to run anyway
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
|
@ -90,11 +98,14 @@ try {
|
||||||
console.info(`WebSSH2 service reading config from: ${configPath}`);
|
console.info(`WebSSH2 service reading config from: ${configPath}`);
|
||||||
// eslint-disable-next-line global-require
|
// eslint-disable-next-line global-require
|
||||||
config = require('read-config-ng')(configPath);
|
config = require('read-config-ng')(configPath);
|
||||||
|
// setup overrides for environment variables
|
||||||
|
setOverrides();
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
`\n\nERROR: Missing config.json for WebSSH2. Current config: ${JSON.stringify(config)}`
|
`\n\nERROR: Missing config.json for WebSSH2. Current config: ${JSON.stringify(config)}`
|
||||||
);
|
);
|
||||||
console.error('\n See config.json.sample for details\n\n');
|
console.error('\n See config.json.sample for details\n\n');
|
||||||
|
setOverrides();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
Loading…
Reference in a new issue