Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import { NextResponse } from "next/server";
import { pingDb } from "@/lib/db/core";
/**
* GET /api/health/ping — Lightweight liveness probe
*
* Delegates to `pingDb()` (Hard Rule #5: no raw SQL in routes) to confirm
* the server process is alive and the database is responsive. Intended
* for high-frequency polling (e.g. MaintenanceBanner) where the heavy
* `/api/monitoring/health` observability snapshot is too expensive.
*
* Returns `{ status: "ok", timestamp, latencyMs }` on success, or HTTP 503 on failure.
* No auth required — this is a public liveness signal.
*/
export const dynamic = "force-dynamic";
export async function GET() {
const startedAt = Date.now();
try {
const alive = pingDb();
if (!alive) {
return NextResponse.json(
{ status: "error", error: "db_query_failed" },
{ status: 503 }
);
}
return NextResponse.json(
{
status: "ok",
timestamp: new Date().toISOString(),
latencyMs: Date.now() - startedAt,
},
{
status: 200,
headers: {
"Cache-Control": "no-store, no-cache, must-revalidate",
},
}
);
} catch (error) {
console.error("[ping] Unexpected error in GET /api/health/ping:", error);
return NextResponse.json(
{ status: "error", error: "ping_failed" },
{ status: 503 }
);
}
}