Files
mcpctl/src/mcpd/src/routes/health.ts
Michal af9f7458fc fix: empty MCPD_BACKUP_REPO crashes mcpd on healthz with ERR_HTTP_HEADERS_SENT
Two bugs: (1) empty string env var treated as enabled (use || instead of ??),
(2) health routes missing return reply causing double-send with onSend hook.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 01:29:45 +00:00

31 lines
825 B
TypeScript

import type { FastifyInstance } from 'fastify';
import { APP_VERSION } from '@mcpctl/shared';
export interface HealthDeps {
checkDb: () => Promise<boolean>;
}
export function registerHealthRoutes(app: FastifyInstance, deps: HealthDeps): void {
app.get('/health', async (_request, reply) => {
const dbOk = await deps.checkDb().catch(() => false);
const status = dbOk ? 'healthy' : 'degraded';
const statusCode = dbOk ? 200 : 503;
return reply.code(statusCode).send({
status,
version: APP_VERSION,
uptime: process.uptime(),
timestamp: new Date().toISOString(),
checks: {
database: dbOk ? 'ok' : 'error',
},
});
});
// Simple liveness probe
app.get('/healthz', async (_request, reply) => {
return reply.code(200).send({ status: 'ok' });
});
}