26 lines
817 B
TypeScript
26 lines
817 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { sql } from "drizzle-orm";
|
|
import { getPayload } from "payload";
|
|
import config from "@payload-config";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
/**
|
|
* Used by the Docker healthcheck (see docker-compose.yml) and by
|
|
* setup.sh/deploy.sh to confirm the app can actually reach Postgres before
|
|
* being considered "up" - not just that the Node process is listening.
|
|
*/
|
|
export async function GET() {
|
|
try {
|
|
const payload = await getPayload({ config });
|
|
await payload.db.drizzle.execute(sql`SELECT 1`);
|
|
return NextResponse.json({ status: "ok", database: "connected" });
|
|
} catch (error) {
|
|
console.error("healthcheck failed", error);
|
|
return NextResponse.json(
|
|
{ status: "error", database: "unreachable" },
|
|
{ status: 503 },
|
|
);
|
|
}
|
|
}
|