mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 07:05:04 +00:00
Gateway: add healthz/readyz probe endpoints for container checks (#31272)
* Gateway: add HTTP liveness/readiness probe routes * Gateway tests: cover probe route auth bypass and methods * Docker Compose: add gateway /healthz healthcheck * Docs: document Docker probe endpoints * Dockerfile: note built-in probe endpoints * Gateway: make probe routes fallback-only to avoid shadowing * Gateway tests: verify probe paths do not shadow plugin routes * Changelog: note gateway container probe endpoints
This commit is contained in:
@@ -73,6 +73,43 @@ function sendJson(res: ServerResponse, status: number, body: unknown) {
|
||||
res.end(JSON.stringify(body));
|
||||
}
|
||||
|
||||
const GATEWAY_PROBE_STATUS_BY_PATH = new Map<string, "live" | "ready">([
|
||||
["/health", "live"],
|
||||
["/healthz", "live"],
|
||||
["/ready", "ready"],
|
||||
["/readyz", "ready"],
|
||||
]);
|
||||
|
||||
function handleGatewayProbeRequest(
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
requestPath: string,
|
||||
): boolean {
|
||||
const status = GATEWAY_PROBE_STATUS_BY_PATH.get(requestPath);
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const method = (req.method ?? "GET").toUpperCase();
|
||||
if (method !== "GET" && method !== "HEAD") {
|
||||
res.statusCode = 405;
|
||||
res.setHeader("Allow", "GET, HEAD");
|
||||
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
res.end("Method Not Allowed");
|
||||
return true;
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||
res.setHeader("Cache-Control", "no-store");
|
||||
if (method === "HEAD") {
|
||||
res.end();
|
||||
return true;
|
||||
}
|
||||
res.end(JSON.stringify({ ok: true, status }));
|
||||
return true;
|
||||
}
|
||||
|
||||
function writeUpgradeAuthFailure(
|
||||
socket: { write: (chunk: string) => void },
|
||||
auth: GatewayAuthResult,
|
||||
@@ -491,6 +528,9 @@ export function createGatewayHttpServer(opts: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (handleGatewayProbeRequest(req, res, requestPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
res.statusCode = 404;
|
||||
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
|
||||
Reference in New Issue
Block a user