import { NextResponse } from "next/server"; // Readiness — 503 when the api liveness is unreachable (web's only readiness // dependency). Unauthenticated by design; no data beyond the check outcome. // TASK-0009 item 4: web → `apps/web/src/app/health/ready/route.ts`. const startedAt = Date.now(); export const dynamic = "force-dynamic"; async function checkApiLiveness(): Promise<{ api: boolean }> { const base = process.env.API_URL ?? "http://localhost:4000"; const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 1000); try { const res = await fetch(`${base}/api/v1/health`, { method: "GET", signal: controller.signal, cache: "no-store" }); return { api: res.ok }; } catch { return { api: false }; } finally { clearTimeout(timer); } } export async function GET() { const checks = await checkApiLiveness(); const ok = checks.api; return NextResponse.json( { status: ok ? "ready" : "not_ready", uptimeSeconds: Math.round((Date.now() - startedAt) / 1000), checks }, { status: ok ? 200 : 503 } ); }