2018-07-31 19:50:18 +02:00
|
|
|
const config = require('./config');
|
|
|
|
const utils = require('./utils');
|
2019-07-07 10:49:34 +02:00
|
|
|
const env = require('./env');
|
2022-10-01 15:32:30 +02:00
|
|
|
const dataDir = require('./data_dir');
|
2019-07-07 10:49:34 +02:00
|
|
|
|
2022-10-01 15:32:30 +02:00
|
|
|
function parseAndValidate(portStr, source) {
|
|
|
|
const portNum = parseInt(portStr);
|
2018-07-31 19:50:18 +02:00
|
|
|
|
2023-03-12 21:37:13 +01:00
|
|
|
if (isNaN(portNum) || portNum < 0 || portNum >= 65536) {
|
|
|
|
console.log(`FATAL ERROR: Invalid port value "${portStr}" from ${source}, should be an integer between 0 and 65536.`);
|
2022-10-01 15:32:30 +02:00
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return portNum;
|
2018-07-31 19:50:18 +02:00
|
|
|
}
|
2022-10-01 15:32:30 +02:00
|
|
|
|
|
|
|
let port;
|
|
|
|
|
|
|
|
if (process.env.TRILIUM_PORT) {
|
|
|
|
port = parseAndValidate(process.env.TRILIUM_PORT, "environment variable TRILIUM_PORT");
|
|
|
|
} else if (utils.isElectron()) {
|
|
|
|
port = env.isDev() ? 37740 : 37840;
|
|
|
|
} else {
|
2022-12-21 15:19:05 +01:00
|
|
|
port = parseAndValidate(config['Network']['port'] || '3000', `Network.port in ${dataDir.CONFIG_INI_PATH}`);
|
2022-08-03 00:19:29 +02:00
|
|
|
}
|
2022-10-01 15:32:30 +02:00
|
|
|
|
|
|
|
module.exports = port;
|