fix(health): check DB connectivity in health endpoint
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"sessionID": "ses_1d89ad89affe987QEXPgCGcx4S",
|
||||
"updatedAt": "2026-05-14T22:39:28.515Z",
|
||||
"updatedAt": "2026-05-14T23:04:32.000Z",
|
||||
"sources": {
|
||||
"background-task": {
|
||||
"state": "idle",
|
||||
"updatedAt": "2026-05-14T22:39:28.515Z"
|
||||
"state": "active",
|
||||
"reason": "1 background task(s) active",
|
||||
"updatedAt": "2026-05-14T23:04:32.000Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-10
@@ -1,15 +1,27 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import { db } from "@/db/client";
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export const GET: APIRoute = () => {
|
||||
return new Response(
|
||||
JSON.stringify({ status: "ok" }),
|
||||
{
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
export const GET: APIRoute = async () => {
|
||||
try {
|
||||
await db.execute(sql`SELECT 1`);
|
||||
return new Response(
|
||||
JSON.stringify({ status: "ok", db: "connected" }),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("[Health] DB connection failed:", err);
|
||||
return new Response(
|
||||
JSON.stringify({ status: "error", db: "disconnected", error: String(err) }),
|
||||
{
|
||||
status: 503,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user