feat: add public health endpoint
This commit is contained in:
@@ -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
@@ -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],
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user