fix(health): check DB connectivity in health endpoint

This commit is contained in:
emil
2026-05-15 02:05:40 +03:00
parent b71902b686
commit b762e2eb66
2 changed files with 26 additions and 13 deletions
@@ -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
View File
@@ -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" },
}
);
}
};