mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
28 lines
816 B
JavaScript
28 lines
816 B
JavaScript
const config = require('./config');
|
|
const utils = require('./utils');
|
|
const env = require('./env');
|
|
const dataDir = require('./data_dir');
|
|
|
|
function parseAndValidate(portStr, source) {
|
|
const portNum = parseInt(portStr);
|
|
|
|
if (!portNum || portNum < 0 || portNum >= 65536) {
|
|
console.log(`FATAL ERROR: Invalid port value "${portStr}" from ${source}, should be a number between 0 and 65536.`);
|
|
process.exit(-1);
|
|
}
|
|
|
|
return portNum;
|
|
}
|
|
|
|
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 {
|
|
port = parseAndValidate(config['Network']['port'] || '3000', "Network.port in " + dataDir.CONFIG_INI_PATH);
|
|
}
|
|
|
|
module.exports = port;
|