Skip to content

Commit 19b633c

Browse files
author
Codex Microtask Operator
committed
Fallback invalid CommandBoard web ports
1 parent 8f46915 commit 19b633c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

apps/commandboard-web/server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const appDirectory = fileURLToPath(new URL(".", import.meta.url));
88
const distDirectory = resolve(appDirectory, "dist");
99
const indexFile = join(distDirectory, "index.html");
1010
const apiServer = createCommandBoardServer();
11-
const port = Number(process.env.PORT ?? 4173);
11+
const port = readPort(process.env.PORT, 4173);
1212

1313
const mimeTypes = {
1414
".css": "text/css; charset=utf-8",
@@ -67,6 +67,11 @@ function resolveStaticPath(pathname) {
6767
return indexFile;
6868
}
6969

70+
function readPort(value, fallback) {
71+
const parsed = Number(value ?? fallback);
72+
return Number.isInteger(parsed) && parsed > 0 && parsed <= 65535 ? parsed : fallback;
73+
}
74+
7075
function sendFile(file, headOnly, response) {
7176
if (!existsSync(file)) {
7277
response.writeHead(500, { "content-type": "text/plain; charset=utf-8" });

0 commit comments

Comments
 (0)