import type { FastifyInstance } from "fastify"; import { sql } from "drizzle-orm"; import { BRAND } from "@app/shared-types"; /** Liveness/readiness för lastbalanserare och Docker healthchecks (spec §58). */ export async function healthRoutes(app: FastifyInstance) { app.get("/healthz", { config: { rateLimit: false } }, async () => ({ ok: true, service: `${BRAND.slug}-api`, timestamp: new Date().toISOString(), })); app.get("/readyz", { config: { rateLimit: false } }, async (_req, reply) => { try { await app.db.execute(sql`SELECT 1`); } catch { return reply.status(503).send({ ok: false, reason: "database" }); } const aamosHealth = await app.aamos.healthCheck(); if (!aamosHealth.ok) { return reply.status(503).send({ ok: false, reason: "aamos", detail: aamosHealth.detail }); } return { ok: true }; }); /** Enkel endpointöversikt i stället för tung OpenAPI-generering (se beslutslogg D-011). */ app.get("/docs", { config: { rateLimit: false } }, async (_req, reply) => { const routes = app.routeCatalog .filter((r) => !r.url.startsWith("/v1/mock-s3")) .sort((a, b) => a.url.localeCompare(b.url) || a.method.localeCompare(b.method)); const rows = routes .map((r) => `
${r.method}${r.url}${routes.length} endpoints. Auth: Authorization: Bearer <accessToken>.
Fullständig referens: docs/api-referens.md i repot.