Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NextResponse } from "next/server";
import { db } from "@/lib/db";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

const DB_TIMEOUT_MS = 3000;
const headers = { "Cache-Control": "no-store" };

// Public health check for status.profullstack.com: one `select 1` with a 3s
// ceiling. No auth and no error details in the response.
export async function GET() {
let timer: ReturnType<typeof setTimeout> | undefined;
try {
await Promise.race([
db().execute("select 1"),
new Promise((_, reject) => {
timer = setTimeout(() => reject(new Error("timeout")), DB_TIMEOUT_MS);
}),
]);
return NextResponse.json({ status: "ok", db: "ok" }, { headers });
} catch {
return NextResponse.json({ status: "error", db: "down" }, { status: 503, headers });
} finally {
clearTimeout(timer);
}
}
Loading