Skip to content

Build your personal knowledge base with Trilium Notes

small fixes / refactoring

zadam8de67b69455c
diff --git a/docker_healthcheck.js b/docker_healthcheck.js
index 7c8258ba67..c5d2555954 100755
--- a/docker_healthcheck.js
+++ b/docker_healthcheck.js
@@ -11,7 +11,8 @@ if (config.https) {
const port = require('./src/services/port');
const host = require('./src/services/host');
-let options = {timeout: 2000};
+const options = { timeout: 2000 };
+
const callback = res => {
console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode === 200) {
@@ -20,7 +21,9 @@ const callback = res => {
process.exit(1);
}
};
+
let request;
+
if (port !== 0) { // TCP socket.
const url = `http://${host}:${port}/api/health-check`;
request = http.request(url, options, callback);
@@ -29,6 +32,7 @@ if (port !== 0) { // TCP socket.
options.path = '/api/health-check';
request = http.request(options, callback);
}
+
request.on("error", err => {
console.log("ERROR");
process.exit(1);
diff --git a/src/services/port.js b/src/services/port.js
index bba42b7c7c..c57f22a5d7 100644
--- a/src/services/port.js
+++ b/src/services/port.js
@@ -6,8 +6,8 @@ const dataDir = require('./data_dir');
function parseAndValidate(portStr, source) {
const portNum = parseInt(portStr);
- if (!portNum && portNum !== 0 || portNum < 0 || portNum >= 65536) {
- console.log(`FATAL ERROR: Invalid port value "${portStr}" from ${source}, should be a number between 0 and 65536.`);
+ 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);
}
diff --git a/src/www b/src/www
index 1bf484520e..136feabf3b 100644
--- a/src/www
+++ b/src/www
@@ -100,14 +100,14 @@ async function startTrilium() {
*/
httpServer.keepAliveTimeout = 120000 * 5;
- const listenTcp = port !== 0;
- if (listenTcp) {
+ const listenOnTcp = port !== 0;
+ if (listenOnTcp) {
httpServer.listen(port, host); // TCP socket.
} else {
httpServer.listen(host); // Unix socket.
}
httpServer.on('error', error => {
- if (!listenTcp || error.syscall !== 'listen') {
+ if (!listenOnTcp || error.syscall !== 'listen') {
throw error;
}
@@ -130,7 +130,7 @@ async function startTrilium() {
)
httpServer.on('listening', () => {
- if (listenTcp) {
+ if (listenOnTcp) {
log.info(`Listening on port ${port}`)
} else {
log.info(`Listening on unix socket ${host}`)