registry
@automindzsheets 01–77shadcn 4.x
SHEET 75

Health (Next.js)

item / server / ops

The Next.js twin of health: framework-free handler plus a two-line route.ts. 200 when every check passes, 503 when any fail, never cached, never leaks.

type
item
files
3
registry deps
none
npm deps
none
env vars
APP_VERSION, GIT_SHA

installs

  • ~/lib/automindz/health.ts
  • ~/app/api/health/route.ts
  • ~/tests/health.test.mts
  • Framework-free createHealthHandler runs under node --test; route.ts is two lines the app edits
  • force-dynamic so Next never statically caches the route
  • Node cannot preempt a blocking sync check — keep sync checks cheap, make slow ones async

Edit app/api/health/route.ts: export const GET = createHealthHandler({ service: "my-app", checks: { db: () => db.healthcheck() }, flags: () => env.flags }) — both optional. The handler reruns every check per request (Cache-Control: no-store; route.ts ships dynamic = "force-dynamic" so Next never caches it) and answers 200 {status, service, version, started_at, uptime_s, checks, flags}, or 503 with status: "degraded" when any check fails. Each check gets a 2000 ms timeout (timeoutMs); a timeout is a failed check — but Node cannot preempt a synchronously blocking check, so keep sync checks cheap and make slow ones async. version resolves option > APP_VERSION > GIT_SHA[:12] > dev. A failing check's error is the constructor name plus one line truncated to 200 chars, never a stack trace. Exempt the path in proxy.ts and point the Dokploy healthcheck at it. Run the shipped test with node --test tests/health.test.mts.

Variations

one state per section

No previews for this item yet.