feat: add /api/health endpoint for healthy.sh monitoring#1
Draft
Manan-Santoki wants to merge 1 commit into
Draft
feat: add /api/health endpoint for healthy.sh monitoring#1Manan-Santoki wants to merge 1 commit into
Manan-Santoki wants to merge 1 commit into
Conversation
Adds GET /api/health for uptime monitoring. Reports overall status plus
a Postgres connectivity check (SELECT 1 via the existing getSql helper,
lazily imported). Returns 200 {status:"ok"} when healthy, 503
{status:"degraded"} when Postgres is configured but unreachable, and a
soft 200 {status:"degraded"} when DATABASE_URL is unset since the
editor and PDF export work without it. Optional HEALTHSH_HEALTH_TOKEN
env var gates check details (Bearer header or ?token= query param);
unauthenticated callers only see {status}.
Also exports getSql from src/lib/db.ts so the route can reuse the
shared client.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
GET /api/health(src/app/api/health/route.ts) so the healthy.sh fleet monitor can probe Binderly. The route runs on the Node.js runtime withdynamic = "force-dynamic"(never cached) and checks Postgres connectivity with aSELECT 1through the repo's existinggetSqlhelper (now exported fromsrc/lib/db.ts). The DB module is lazily imported inside the handler, so a missing or brokenDATABASE_URLcan never crash module load or the build.Response contract
{ "status": "ok", "service": "binderly", "checks": { "postgres": { "ok": true, "latency_ms": 12 } } }{ "status": "degraded", "service": "binderly", "checks": { "postgres": { "ok": false, "error": "<msg>" } } }DATABASE_URLunset{ "status": "degraded", "service": "binderly", "checks": { "postgres": { "ok": false, "error": "unconfigured" } } }DATABASE_URLunset is a soft degradation (HTTP 200): the editor and PDF export work fine without Postgres — only sharing needs it.Optional token gating
If the env var
HEALTHSH_HEALTH_TOKENis set, requests must present it viaAuthorization: Bearer <token>or?token=<token>. Requests without a valid token get the same HTTP status code but a body of only{ "status": "..." }— check details (error messages, latency) are omitted. If the env var is unset, the endpoint is fully open (it exposes no secrets either way, but error strings can hint at infra details).How healthy.sh consumes this
The monitor registers a
json_healthcheck againsthttps://<host>/api/healthasserting$.status == "ok", with the HTTP status code as a secondary signal (200 = up/soft-degraded, 503 = postgres down).latency_msis recorded as a metric.Testing
Verified locally with
pnpm tsc --noEmit(clean).🤖 Generated with Claude Code