mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 14:37:26 +00:00
Fallback invalid CommandBoard web ports (#37)
Co-authored-by: Codex Microtask Operator <codex-microtask@example.com>
This commit is contained in:
parent
ad3926a006
commit
307095d5e9
1 changed files with 6 additions and 1 deletions
|
|
@ -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" });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue