feat: add public health endpoint

This commit is contained in:
2026-09-28 21:03:46 +09:00
parent 423d9edbfa
commit 8985ef9fff
2 changed files with 10 additions and 1 deletions
+2
View File
@@ -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 `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. 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 ## Requirements and setup
Use Nix, or Node.js `>=22.12.0` with pnpm `11.9.0`. The committed `.npmrc` Use Nix, or Node.js `>=22.12.0` with pnpm `11.9.0`. The committed `.npmrc`
+8 -1
View File
@@ -1,5 +1,12 @@
import { createCsrfMiddleware, createMiddleware, createStart } from "@tanstack/react-start"; 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 ownerAccess = createMiddleware().server(async ({ request, next }) => {
const { checkAccess, readAccessConfig } = await import("./features/access/policy.server"); const { checkAccess, readAccessConfig } = await import("./features/access/policy.server");
return checkAccess(request, readAccessConfig()) ?? next(); return checkAccess(request, readAccessConfig()) ?? next();
@@ -23,5 +30,5 @@ const storage = createMiddleware().server(async ({ next }) => {
}); });
export const startInstance = createStart(() => ({ export const startInstance = createStart(() => ({
requestMiddleware: [ownerAccess, csrf, storage, appSession], requestMiddleware: [health, ownerAccess, csrf, storage, appSession],
})); }));