import { connection } from "next/server"; import { getDb, pingDb } from "@/lib/db/mongo"; import { APP_COMMIT, APP_VERSION } from "@/lib/version"; /** * Sağlık kontrolü (Dokploy / Docker HEALTHCHECK). Veritabanına erişilemezse 503. * İç hata detayı döndürülmez. */ export async function GET() { // Cache Components açıkken GET handler'ı build'de prerender edilmesin. await connection(); const dbOk = await pingDb(); // Transaction'lar için replica set şart; adı yoksa (standalone) null. let replicaSet: string | null = null; if (dbOk) { try { const hello = await getDb().admin().command({ hello: 1 }, { timeoutMS: 2_000 }); replicaSet = typeof hello.setName === "string" ? hello.setName : null; } catch { replicaSet = null; } } return Response.json( { status: dbOk ? "ok" : "degraded", db: dbOk ? "ok" : "unreachable", replicaSet, version: APP_VERSION, commit: APP_COMMIT, time: new Date().toISOString(), }, { status: dbOk ? 200 : 503, headers: { "Cache-Control": "no-store" } }, ); }