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>
31 lines
825 B
TypeScript
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' });
|
|
});
|
|
}
|