Fallback invalid CommandBoard web ports (#37)

Co-authored-by: Codex Microtask Operator <codex-microtask@example.com>
This commit is contained in:
Autowebassat-blip 2026-06-14 07:58:10 +02:00 committed by GitHub
parent ad3926a006
commit 307095d5e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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