fix: harden cloud api port env handling

This commit is contained in:
Codex
2026-05-24 18:03:09 +00:00
parent 89b5773349
commit fa216f1cd8
4 changed files with 17 additions and 1 deletions
+7 -1
View File
@@ -2,7 +2,7 @@
import { createCloudApiServer } from "../../internal/cloud/server.mjs";
const host = process.env.HWLAB_CLOUD_API_HOST || "0.0.0.0";
const port = Number.parseInt(process.env.HWLAB_CLOUD_API_PORT || process.env.PORT || "6667", 10);
const port = parsePort(process.env.HWLAB_CLOUD_API_PORT, parsePort(process.env.PORT, 6667));
const commitId = process.env.HWLAB_COMMIT_ID || process.env.HWLAB_GIT_SHA;
const codeAgentTimeoutMs = parseTimeout(process.env.HWLAB_CODE_AGENT_TIMEOUT_MS, 600000, {
min: 1000,
@@ -32,6 +32,12 @@ function parseTimeout(value, fallback, { min, max }) {
return Math.min(Math.max(parsed, min), max);
}
function parsePort(value, fallback) {
const parsed = Number.parseInt(value || "", 10);
if (!Number.isInteger(parsed) || parsed < 0 || parsed >= 65536) return fallback;
return parsed;
}
server.listen(port, host, () => {
const address = server.address();
const resolvedPort = typeof address === "object" && address ? address.port : port;