mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 15:49:00 +02:00

this value cannot change during runtime, => there is no need to have these checks as dynamic function, instead just export the boolean value directly
27 lines
812 B
TypeScript
27 lines
812 B
TypeScript
import config from "./config.js";
|
|
import { isDev, isElectron } from "./utils.js";
|
|
import dataDir from "./data_dir.js";
|
|
|
|
function parseAndValidate(portStr: string, source: string) {
|
|
const portNum = parseInt(portStr);
|
|
|
|
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.`);
|
|
process.exit(-1);
|
|
}
|
|
|
|
return portNum;
|
|
}
|
|
|
|
let port: number;
|
|
|
|
if (process.env.TRILIUM_PORT) {
|
|
port = parseAndValidate(process.env.TRILIUM_PORT, "environment variable TRILIUM_PORT");
|
|
} else if (isElectron) {
|
|
port = isDev ? 37740 : 37840;
|
|
} else {
|
|
port = parseAndValidate(config["Network"]["port"] || "3000", `Network.port in ${dataDir.CONFIG_INI_PATH}`);
|
|
}
|
|
|
|
export default port;
|