From 8985ef9fff80d582f475015196200c9455717f5a Mon Sep 17 00:00:00 2001 From: yuta Date: Mon, 28 Sep 2026 21:03:46 +0900 Subject: [PATCH] feat: add public health endpoint --- README.md | 2 ++ src/start.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fb2003..de9c5cb 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ use opens account setup, followed by a short onboarding. Run `nix develop -c pnpm account:setup` on the server to obtain the private setup code. See [owner login](docs/login.md) for configuration, sessions, and limits. +`GET /health` returns `{"status":"ok"}` without authentication or database access. + ## Requirements and setup Use Nix, or Node.js `>=22.12.0` with pnpm `11.9.0`. The committed `.npmrc` diff --git a/src/start.ts b/src/start.ts index 0ff04ed..fb924bd 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,5 +1,12 @@ import { createCsrfMiddleware, createMiddleware, createStart } from "@tanstack/react-start"; +const health = createMiddleware().server(({ request, next }) => { + if (request.method === "GET" && new URL(request.url).pathname === "/health") { + return Response.json({ status: "ok" }, { headers: { "Cache-Control": "no-store" } }); + } + return next(); +}); + const ownerAccess = createMiddleware().server(async ({ request, next }) => { const { checkAccess, readAccessConfig } = await import("./features/access/policy.server"); return checkAccess(request, readAccessConfig()) ?? next(); @@ -23,5 +30,5 @@ const storage = createMiddleware().server(async ({ next }) => { }); export const startInstance = createStart(() => ({ - requestMiddleware: [ownerAccess, csrf, storage, appSession], + requestMiddleware: [health, ownerAccess, csrf, storage, appSession], }));