Skip to content

feat(server): add opt-in /health/live and /health/ready endpoints - #351

Merged
Espoir-Loem merged 3 commits into
NexyPy:mainfrom
tharunsridhar:feature/health-endpoint
Nov 8, 2026
Merged

Espoir-Loem merged 3 commits into
NexyPy:mainfrom
tharunsridhar:feature/health-endpoint

Conversation

@tharunsridhar

@tharunsridhar tharunsridhar commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds an opt-in useHealth setting that serves two endpoints for load balancers and Kubernetes probes.

  • GET /health/live answers 200 while the process answers.
  • GET /health/ready answers 200 once the application has started, and 503 while it starts or is asked to stop. The phase is read from the ASGI lifespan messages, so it follows the real startup and shutdown.

The middleware is the outermost one, so a probe is answered before the access log, useTrustedHost and useHTTPSRedirect. A probe sent over HTTP to the address of a pod is therefore not refused. No route is added, so the endpoints stay out of the OpenAPI schema. useHealth is False by default, so no path is taken from a project that does not set it.

docs/deployment/README.md gets a "Built-in endpoints" section with a Kubernetes Deployment probe example, and docs/reference/config.md gets a useHealth row.

Fixes #86

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes existing behavior)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test addition or improvement

Checklist

  • Tests pass (python -m pytest tests/ -v), apart from 6 test_make_com_media tests that also fail on main on my machine because the DejaVu fonts are missing
  • Lint passes (ruff check nexy/)
  • Type checking passes (python -m mypy nexy --strict)
  • Formatting is correct (ruff format nexy/ --check)
  • New tests cover my changes
  • Documentation is updated (if applicable)
  • Commit messages follow Conventional Commits

Additional context

  • Tests are in tests/unit/nexy/routers/test_health.py: the starting, ready and stopping lifecycle, the access log, the host check and HTTPS redirect, the OpenAPI schema, and off by default.
  • Translations under docs/<lang>/ were regenerated with scripts/translate_docs.py for the two pages I changed (33 files, in their own commit). Only the English pages are hand-written.
  • I also ran it on a real uvicorn server: both endpoints answer 200 after startup and are absent from the access log.

useHealth = True serves two endpoints for load balancers and Kubernetes
probes. /health/live answers 200 while the process answers. /health/ready
answers 200 once the application has started and 503 while it starts or
is asked to stop, read from the ASGI lifespan messages.

The middleware is the outermost one, so a probe skips the access log, the
trusted host check and the HTTPS redirect, and the endpoints are not in the
OpenAPI schema. The setting is off by default: no path is taken from a
project that does not set it.

Closes #86
Regenerated with scripts/translate_docs.py for docs/deployment/README.md
and docs/reference/config.md in every site language.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A health endpoint for load balancers and Kubernetes probes

2 participants