Files
0pt/app/api/ready/route.ts
T

35 lines
1.3 KiB
TypeScript

import { NextResponse } from "next/server";
import { checkAllDependencies, isReady } from "@/lib/health-checks";
// GET /api/ready — readiness (BACKLOG P0-3, CD-04/OBS-04: "no /ready route
// existed at all").
//
// Unlike GET /api/health (liveness -- always 200 while the process can
// respond), this fails closed: 503 whenever a load-bearing dependency isn't
// both configured AND actually reachable. Point a load balancer / Coolify
// readiness probe at this route, not /api/health, to stop routing traffic to
// an instance whose database is down without restarting it.
//
// Load-bearing by absence: only the database (see
// `lib/health-checks.ts#isReady`) -- engine/stripe/queue are optional
// integrations 0pt is designed to run without. Load-bearing by FAILURE: all
// of them. A dependency somebody configured and that then fails a live round
// trip makes this instance not-ready, whichever one it is.
export async function GET() {
const deps = await checkAllDependencies();
const ready = isReady(deps);
return NextResponse.json(
{
ready,
service: "0pt-web",
db: deps.db.status,
queue: deps.queue.status,
engine: deps.engine.status,
stripe: deps.stripe.status,
ts: new Date().toISOString(),
},
{ status: ready ? 200 : 503 },
);
}