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", "sessionID": "ses_1d89ad89affe987QEXPgCGcx4S",
"updatedAt": "2026-05-14T22:39:28.515Z", "updatedAt": "2026-05-14T23:04:32.000Z",
"sources": { "sources": {
"background-task": { "background-task": {
"state": "idle", "state": "active",
"updatedAt": "2026-05-14T22:39:28.515Z" "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 type { APIRoute } from "astro";
import { db } from "@/db/client";
import { sql } from "drizzle-orm";
export const prerender = false; export const prerender = false;
export const GET: APIRoute = () => { export const GET: APIRoute = async () => {
return new Response( try {
JSON.stringify({ status: "ok" }), await db.execute(sql`SELECT 1`);
{ return new Response(
status: 200, JSON.stringify({ status: "ok", db: "connected" }),
headers: { {
"Content-Type": "application/json", 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" },
}
);
}
}; };