mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 21:02:12 +03:00
fix(api-bridge): validate configured proxy timeout value
This commit is contained in:
@@ -2,7 +2,23 @@ import http from "node:http";
|
||||
import type { IncomingMessage, ServerResponse } from "node:http";
|
||||
import { getRuntimePorts } from "@/lib/runtime/ports";
|
||||
|
||||
const PROXY_TIMEOUT_MS = Number(process.env.API_BRIDGE_PROXY_TIMEOUT_MS || "30000");
|
||||
const DEFAULT_PROXY_TIMEOUT_MS = 30_000;
|
||||
|
||||
function parseProxyTimeoutMs(raw: string | undefined): number {
|
||||
if (raw == null || raw.trim() === "") return DEFAULT_PROXY_TIMEOUT_MS;
|
||||
const parsed = Number(raw);
|
||||
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
console.warn(
|
||||
`[API Bridge] Invalid API_BRIDGE_PROXY_TIMEOUT_MS=\"${raw}\". Using default ${DEFAULT_PROXY_TIMEOUT_MS}ms.`
|
||||
);
|
||||
return DEFAULT_PROXY_TIMEOUT_MS;
|
||||
}
|
||||
|
||||
return Math.floor(parsed);
|
||||
}
|
||||
|
||||
const PROXY_TIMEOUT_MS = parseProxyTimeoutMs(process.env.API_BRIDGE_PROXY_TIMEOUT_MS);
|
||||
|
||||
const OPENAI_COMPAT_PATHS = [
|
||||
/^\/v1(?:\/|$)/,
|
||||
|
||||
Reference in New Issue
Block a user