fix(backend): Resolve duplicate /health route registration

- Move /health route into registerHealthRoutes function for backward compatibility
- Update index.ts to only call registerHealthRoutes once
- Now provides 3 endpoints: /health, /health/liveness, /health/readiness

Fixes: FastifyError Method 'GET' already declared for route '/health'
This commit is contained in:
2025-11-18 07:39:47 +08:00
parent 31d555f7bb
commit 61a45aa917
2 changed files with 39 additions and 21 deletions

View File

@@ -10,6 +10,8 @@ import knowledgeBaseRoutes from './legacy/routes/knowledgeBases.js';
import { chatRoutes } from './legacy/routes/chatRoutes.js';
import { batchRoutes } from './legacy/routes/batchRoutes.js';
import reviewRoutes from './legacy/routes/reviewRoutes.js';
import { registerHealthRoutes } from './common/health/index.js';
import { logger } from './common/logging/index.js';
// 全局处理BigInt序列化
@@ -52,24 +54,12 @@ await fastify.register(multipart, {
console.log('✅ 文件上传插件已配置: 最大文件大小 10MB');
// 健康检查路由
fastify.get('/health', async () => {
// 检查数据库连接
let dbStatus = 'unknown';
try {
await prisma.$queryRaw`SELECT 1`;
dbStatus = 'connected';
} catch {
dbStatus = 'disconnected';
}
return {
status: 'ok',
database: dbStatus,
timestamp: new Date().toISOString(),
uptime: process.uptime(),
};
});
// ============================================
// 【平台基础设施】健康检查路由
// ============================================
// 注册健康检查路由(/health, /health/liveness, /health/readiness
await registerHealthRoutes(fastify);
logger.info('✅ 健康检查路由已注册');
// API路由前缀
fastify.get('/api/v1', async () => {