fix: harden cloud api port env handling
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user