mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 14:57:28 +00:00
Fallback invalid CommandBoard API ports (#39)
Co-authored-by: Codex Microtask Operator <codex-microtask@example.com>
This commit is contained in:
parent
e89c10cc80
commit
3afda8c147
2 changed files with 14 additions and 2 deletions
|
|
@ -396,7 +396,7 @@ function formattedDiscoverMatch(format: "rss" | "opml" | "atom" | "json-feed", e
|
|||
}
|
||||
}
|
||||
|
||||
export function startCommandBoardServer(port = Number(process.env.PORT ?? 4010)) {
|
||||
export function startCommandBoardServer(port = readPort(process.env.PORT, 4010)) {
|
||||
const server = createCommandBoardServer();
|
||||
server.listen(port, () => {
|
||||
console.log(`CommandBoard.run API listening on http://localhost:${port}`);
|
||||
|
|
@ -404,6 +404,11 @@ export function startCommandBoardServer(port = Number(process.env.PORT ?? 4010))
|
|||
return server;
|
||||
}
|
||||
|
||||
export function readPort(value: string | undefined, fallback: number) {
|
||||
const parsed = Number(value ?? fallback);
|
||||
return Number.isInteger(parsed) && parsed > 0 && parsed <= 65535 ? parsed : fallback;
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
startCommandBoardServer();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue