import { sql } from "drizzle-orm"; import { connection } from "next/server"; import { getDb } from "@/db/client"; import { checkReadiness } from "@/lib/health/readiness"; import { getRedisClient } from "@/lib/redis/client"; const NO_STORE_HEADERS = { "Cache-Control": "no-store" }; export async function GET(request: Request) { await connection(); const deploymentId = process.env.NEXT_DEPLOYMENT_ID || "unknown"; const readiness = new URL(request.url).searchParams.get("ready") === "1"; if (!readiness) { return Response.json( { status: "ok", deploymentId }, { headers: NO_STORE_HEADERS }, ); } const timeout = Number(process.env.HEALTHCHECK_TIMEOUT_MS || 2_500); const result = await checkReadiness( { database: async () => { await getDb().execute(sql`select 1`); }, redis: async () => { const client = await getRedisClient(); await client.ping(); }, }, Number.isFinite(timeout) ? timeout : 2_500, ); return Response.json( { ...result, deploymentId }, { status: result.status === "ready" ? 200 : 503, headers: NO_STORE_HEADERS, }, ); }