mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix(api-bridge): make proxy timeout configurable via env (#332)
Add API_BRIDGE_PROXY_TIMEOUT_MS env var to configure the api-bridge proxy timeout. Default remains 30000ms for backward compatibility. Handles invalid values with a warning log. Co-authored-by: hijak <54431520+hijak@users.noreply.github.com>
This commit is contained in:
@@ -166,6 +166,8 @@ GEMINI_CLI_USER_AGENT=google-api-nodejs-client/9.15.1
|
||||
# Timeout settings
|
||||
# FETCH_TIMEOUT_MS=120000
|
||||
# STREAM_IDLE_TIMEOUT_MS=60000
|
||||
# API bridge timeout for /v1 proxy requests (default: 30000)
|
||||
# API_BRIDGE_PROXY_TIMEOUT_MS=120000
|
||||
|
||||
# CORS configuration (default: * allows all origins)
|
||||
# CORS_ORIGINS=*
|
||||
|
||||
@@ -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 = 30_000; // 30s timeout to prevent resource exhaustion
|
||||
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