1import { NextResponse } from "next/server";
2
3
4
5
6
7const startedAt = Date.now();
8
9export const dynamic = "force-dynamic";
10
11async function checkApiLiveness(): Promise<{ api: boolean }> {
12 const base = process.env.API_URL ?? "http://localhost:4000";
13 const controller = new AbortController();
14 const timer = setTimeout(() => controller.abort(), 1000);
15 try {
16 const res = await fetch(`${base}/api/v1/health`, {
17 method: "GET",
18 signal: controller.signal,
19 cache: "no-store"
20 });
21 return { api: res.ok };
22 } catch {
23 return { api: false };
24 } finally {
25 clearTimeout(timer);
26 }
27}
28
29export async function GET() {
30 const checks = await checkApiLiveness();
31 const ok = checks.api;
32 return NextResponse.json(
33 {
34 status: ok ? "ready" : "not_ready",
35 uptimeSeconds: Math.round((Date.now() - startedAt) / 1000),
36 checks
37 },
38 { status: ok ? 200 : 503 }
39 );
40}
41