fix(health): check DB connectivity in health endpoint
This commit is contained in:
@@ -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
@@ -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" },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user