From 208e2153e33f926622b15513294443fb384970ca Mon Sep 17 00:00:00 2001 From: Labyricorn Date: Thu, 23 Jul 2026 13:47:39 -0700 Subject: [PATCH] Make production listener configurable --- deploy/labyricorn-control-plane.service | 2 ++ server.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/deploy/labyricorn-control-plane.service b/deploy/labyricorn-control-plane.service index 5486932..2afc557 100644 --- a/deploy/labyricorn-control-plane.service +++ b/deploy/labyricorn-control-plane.service @@ -9,6 +9,8 @@ User=website-engine Group=website-engine WorkingDirectory=/opt/website-engine-control-plane Environment=NODE_ENV=production +Environment=HOST=127.0.0.1 +Environment=PORT=3000 Environment=LABYRICORN_BUILD_ROOT=/var/lib/website-engine/builds ExecStart=/usr/bin/node /opt/website-engine-control-plane/dist/server.cjs Restart=on-failure diff --git a/server.ts b/server.ts index 9f3defb..9b3f2af 100644 --- a/server.ts +++ b/server.ts @@ -12,7 +12,12 @@ const execAsync = promisify(exec); async function startServer() { const app = express(); - const PORT = 3000; + const port = Number.parseInt(process.env.PORT ?? "3000", 10); + const host = process.env.HOST ?? "0.0.0.0"; + + if (!Number.isInteger(port) || port < 1 || port > 65535) { + throw new Error(`Invalid PORT value: ${process.env.PORT}`); + } app.use(express.json()); @@ -756,8 +761,8 @@ async function startServer() { }); } - app.listen(PORT, "0.0.0.0", () => { - console.log(`Labyricorn Control Plane running on http://0.0.0.0:${PORT}`); + app.listen(port, host, () => { + console.log(`Labyricorn Control Plane running on http://${host}:${port}`); }); }