mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
fix: polish split-port implementation for merge
- Add 30s timeout to API bridge proxy requests to prevent resource exhaustion - Extract healthcheck.mjs script (replaces inline node -e in Dockerfile + compose files) - Add unit tests for runtime port resolution (14 tests, parsePort + resolveRuntimePorts) - Fix formatting in declare global block
This commit is contained in:
@@ -2,6 +2,8 @@ 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 OPENAI_COMPAT_PATHS = [
|
||||
/^\/v1(?:\/|$)/,
|
||||
/^\/chat\/completions(?:\?|$)/,
|
||||
@@ -25,6 +27,7 @@ function proxyRequest(req: IncomingMessage, res: ServerResponse, dashboardPort:
|
||||
...req.headers,
|
||||
host: `127.0.0.1:${dashboardPort}`,
|
||||
},
|
||||
timeout: PROXY_TIMEOUT_MS,
|
||||
},
|
||||
(targetRes) => {
|
||||
res.writeHead(targetRes.statusCode || 502, targetRes.headers);
|
||||
@@ -32,6 +35,18 @@ function proxyRequest(req: IncomingMessage, res: ServerResponse, dashboardPort:
|
||||
}
|
||||
);
|
||||
|
||||
targetReq.on("timeout", () => {
|
||||
targetReq.destroy();
|
||||
if (res.headersSent) return;
|
||||
res.writeHead(504, { "content-type": "application/json" });
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
error: "api_bridge_timeout",
|
||||
detail: `Proxy request timed out after ${PROXY_TIMEOUT_MS}ms`,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
targetReq.on("error", (error) => {
|
||||
if (res.headersSent) return;
|
||||
res.writeHead(502, { "content-type": "application/json" });
|
||||
|
||||
Reference in New Issue
Block a user