From 0aef5b4ddfe6803ceb25dcff713a230a68e4dce8 Mon Sep 17 00:00:00 2001 From: Shahmir Noorani Date: Mon, 24 Aug 2026 12:28:43 -0500 Subject: [PATCH 1/2] For healthcheck, get the port dynamically from config.json instead of hard-coding to 5150 --- Dockerfile | 3 ++- docker/healthcheck.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 docker/healthcheck.js diff --git a/Dockerfile b/Dockerfile index a8fc872..6102855 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,8 @@ USER node EXPOSE 5150 5151 # Healthcheck: perform lightweight HTTP request to ensure app responding +COPY docker/healthcheck.js /usr/local/bin/healthcheck.js HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=5 \ - CMD curl -fsS http://127.0.0.1:5150/config/appVersion?health || exit 1 + CMD node /usr/local/bin/healthcheck.js ENTRYPOINT ["node", "dist/app.js"] diff --git a/docker/healthcheck.js b/docker/healthcheck.js new file mode 100644 index 0000000..febb79a --- /dev/null +++ b/docker/healthcheck.js @@ -0,0 +1,43 @@ +const fs = require("fs"); +const http = require("http"); + +const CONFIG_FILE = "/app/config.json"; +const DEFAULT_PORT = 5150; +const HEALTH_PATH = "/config/appVersion?health"; + +let port = DEFAULT_PORT; + +try { + const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8")); + + port = config.web?.servers?.http?.port ?? DEFAULT_PORT; +} catch { + // Use the default port if the config is unavailable or invalid. +} + +const request = http.get( + { + host: "127.0.0.1", + port, + path: HEALTH_PATH, + timeout: 5000, + }, + (response) => { + response.resume(); + + if (response.statusCode >= 200 && response.statusCode < 300) { + process.exit(0); + } + + process.exit(1); + } +); + +request.on("error", () => { + process.exit(1); +}); + +request.on("timeout", () => { + request.destroy(); + process.exit(1); +}); From 5a48a64d59229cf5f7f72e2c3877b17c65ef0202 Mon Sep 17 00:00:00 2001 From: Shahmir Noorani Date: Mon, 24 Aug 2026 12:42:44 -0500 Subject: [PATCH 2/2] Tweak health check in compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3ce5650..813431e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: - njspc-dash-logs:/app/logs - njspc-dash-uploads:/app/uploads healthcheck: - test: [ "CMD", "node", "-e", "require('net').createConnection({host:'127.0.0.1',port:5150},c=>{c.end();process.exit(0)}).on('error',()=>process.exit(1))" ] + test: ["CMD", "node", "/usr/local/bin/healthcheck.js"] interval: 60s timeout: 5s start_period: 30s