33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import type { BasePayload } from 'payload';
|
|
type CreateHealthRouteArgs = {
|
|
/**
|
|
* Collection to ping for a real DB round-trip. Default 'pages'. Pick any
|
|
* collection that always exists in the project.
|
|
*/
|
|
collection?: string;
|
|
/**
|
|
* Optional extra checks merged into the body (e.g. a cache or queue ping).
|
|
* Throwing marks the whole healthcheck unhealthy.
|
|
*/
|
|
extra?: () => Promise<Record<string, unknown>>;
|
|
/** Same cached accessor the rest of the app uses. */
|
|
getCachedPayload: () => Promise<BasePayload>;
|
|
};
|
|
/**
|
|
* A liveness/readiness route for Coolify/Docker healthchecks and uptime
|
|
* monitors. Does a real DB round-trip (not just "process is up") and returns
|
|
* 200 when reachable, 503 when not — so an orchestrator can restart or hold
|
|
* traffic off a container whose database is down.
|
|
*
|
|
* // app/api/health/route.ts
|
|
* import { createHealthRoute } from '@intecion/ipal-kit'
|
|
* import { getCachedPayload } from '@/lib/content'
|
|
* export const dynamic = 'force-dynamic' // never prerender/cache a healthcheck
|
|
* export const GET = createHealthRoute({ getCachedPayload })
|
|
*
|
|
* Point Coolify's healthcheck at /api/health. Uses the global `Response`
|
|
* (standard in Next route handlers) — no next/server import, peer-dep clean.
|
|
*/
|
|
export declare function createHealthRoute(args: CreateHealthRouteArgs): () => Promise<Response>;
|
|
export {};
|