Files
buzz-sheet/app/api/health/route.ts
T
gunshiz 87e6bcd96f
CI / Verify and audit (push) Successful in 2m33s
CI / Build, scan and deploy immutable images (push) Failing after 1m29s
feat : 6 astra improve it
2026-09-22 18:28:18 +07:00

42 lines
1.1 KiB
TypeScript

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,
},
);
}