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

Health (FastAPI)

item / server / ops

The one GET /api/health every Dokploy app needs: reruns every check per request, 200 when all pass, 503 when any fail, never caches, never leaks an env value or a stack trace.

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

installs

  • ~/backend/health.py
  • ~/backend/tests/test_health.py
  • Every request reruns every check; Cache-Control: no-store, 200 or 503 with the same body shape
  • A failing check leaks only its exception class plus one 200-char line — no env, no DSN, no stack
  • version resolves arg > APP_VERSION > GIT_SHA[:12] > dev; each check bounded by a 2 s timeout

Mount with app.include_router(health.router(service="my-app", checks={"db": db.healthcheck}, flags=lambda: vars(env.flags))) — checks and flags are optional, so a bare mount still answers 200. GET /api/health reruns every check on every request (Cache-Control: no-store) and answers 200 {status, service, version, started_at, uptime_s, checks, flags}, or 503 with status: "degraded" when any check fails — what Dokploy/Traefik and uptime monitors key on. Each check gets a 2 s timeout (timeout_s); a timeout is a failed check, not a hung endpoint. version resolves arg > APP_VERSION > GIT_SHA[:12] > dev. A failing check's error is the exception class plus one line truncated to 200 chars — never a stack trace or an env value, so keep secrets out of check messages. Exempt the path from auth middleware and point the Dokploy healthcheck at it.

Variations

one state per section

No previews for this item yet.