From b762e2eb66bce07e582168f700b692240c621d1d Mon Sep 17 00:00:00 2001 From: emil Date: Fri, 15 May 2026 02:05:40 +0300 Subject: [PATCH] fix(health): check DB connectivity in health endpoint --- .../ses_1d89ad89affe987QEXPgCGcx4S.json | 7 ++-- src/pages/api/health.ts | 32 +++++++++++++------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.sisyphus/run-continuation/ses_1d89ad89affe987QEXPgCGcx4S.json b/.sisyphus/run-continuation/ses_1d89ad89affe987QEXPgCGcx4S.json index 8d77513..bbdd62d 100644 --- a/.sisyphus/run-continuation/ses_1d89ad89affe987QEXPgCGcx4S.json +++ b/.sisyphus/run-continuation/ses_1d89ad89affe987QEXPgCGcx4S.json @@ -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" } } } \ No newline at end of file diff --git a/src/pages/api/health.ts b/src/pages/api/health.ts index 5c0ed98..9598622 100644 --- a/src/pages/api/health.ts +++ b/src/pages/api/health.ts @@ -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" }, + } + ); + } };