Fallback invalid CommandBoard web ports

This commit is contained in:
Codex Microtask Operator 2026-06-13 01:21:16 +02:00
parent 8f4691584c
commit 19b633c524

View file

@ -8,7 +8,7 @@ const appDirectory = fileURLToPath(new URL(".", import.meta.url));
const distDirectory = resolve(appDirectory, "dist"); const distDirectory = resolve(appDirectory, "dist");
const indexFile = join(distDirectory, "index.html"); const indexFile = join(distDirectory, "index.html");
const apiServer = createCommandBoardServer(); const apiServer = createCommandBoardServer();
const port = Number(process.env.PORT ?? 4173); const port = readPort(process.env.PORT, 4173);
const mimeTypes = { const mimeTypes = {
".css": "text/css; charset=utf-8", ".css": "text/css; charset=utf-8",
@ -67,6 +67,11 @@ function resolveStaticPath(pathname) {
return indexFile; return indexFile;
} }
function readPort(value, fallback) {
const parsed = Number(value ?? fallback);
return Number.isInteger(parsed) && parsed > 0 && parsed <= 65535 ? parsed : fallback;
}
function sendFile(file, headOnly, response) { function sendFile(file, headOnly, response) {
if (!existsSync(file)) { if (!existsSync(file)) {
response.writeHead(500, { "content-type": "text/plain; charset=utf-8" }); response.writeHead(500, { "content-type": "text/plain; charset=utf-8" });