import { FastifyInstance } from 'fastify'; import prisma from '../../config/database'; export async function healthRoutes(app: FastifyInstance): Promise { // 基础健康检查 app.get('/health', async (request, reply) => { return { success: true, data: { status: 'ok', timestamp: new Date().toISOString(), version: '1.0.0', }, }; }); // 详细健康检查(包括数据库) app.get('/health/detailed', async (request, reply) => { const checks: Record = { server: 'ok', }; // 检查数据库连接 try { await prisma.$queryRaw`SELECT 1`; checks.database = 'ok'; } catch (error) { checks.database = 'error'; } const allOk = Object.values(checks).every((v) => v === 'ok'); return { success: allOk, data: { status: allOk ? 'ok' : 'degraded', timestamp: new Date().toISOString(), version: '1.0.0', checks, }, }; }); }