Files
accounted/app/api/v1/health/route.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

62 lines
1.8 KiB
TypeScript

/**
* GET /api/v1/health: public health check.
*
* Returns service status. No auth required. Used by load balancers, uptime
* checks, and as a smoke test for the v1 wrapper itself.
*/
import { z } from 'zod'
import { ok } from '@/lib/api/v1/response'
import { registerEndpoint, dataEnvelope } from '@/lib/api/v1/registry'
import { API_V1_VERSION } from '@/lib/api/v1/version'
import { withApiV1 } from '@/lib/api/v1/with-api-v1'
const HealthResponse = z.object({
status: z.enum(['ok', 'degraded']),
service: z.literal('gnubok'),
api_version: z.string(),
timestamp: z.string(),
})
registerEndpoint({
operation: 'health.check',
method: 'GET',
path: '/api/v1/health',
summary: 'Health check.',
description: 'Reports the API is reachable and what version is currently served. Public; no auth required.',
useWhen: 'You want to verify connectivity, latency, or which API version is live before issuing other requests.',
doNotUseFor: 'Anything that needs authenticated data. This endpoint returns no company-specific information.',
pitfalls: [
'A 200 here only means the API process responds: downstream Postgres/Supabase may still be degraded.',
],
example: {
response: {
data: {
status: 'ok',
service: 'gnubok',
api_version: '2026-05-12',
timestamp: '2026-05-12T16:25:06Z',
},
meta: { request_id: 'req_…', api_version: '2026-05-12' },
},
},
scope: null,
risk: 'low',
idempotent: true,
reversible: false,
dryRunSupported: false,
response: { success: dataEnvelope(HealthResponse) },
})
export const GET = withApiV1('health.check', async (_request, ctx) => {
return ok(
{
status: 'ok' as const,
service: 'gnubok' as const,
api_version: API_V1_VERSION,
timestamp: new Date().toISOString(),
},
{ requestId: ctx.requestId },
)
})