diff --git a/src/app/api/keyword-cloud/health/route.ts b/src/app/api/keyword-cloud/health/route.ts new file mode 100644 index 0000000..5f2ccd8 --- /dev/null +++ b/src/app/api/keyword-cloud/health/route.ts @@ -0,0 +1,53 @@ +import { NextResponse } from 'next/server'; +import { prisma } from '@/lib/prisma'; + +export const dynamic = 'force-dynamic'; + +/** + * GET /api/keyword-cloud/health + * 健康检查端点(用于监控) + */ +export async function GET() { + try { + // 检查数据库连接 + await prisma.$queryRaw`SELECT 1`; + + // 统计数据 + const quarterCount = await prisma.quarter.count(); + const keywordCount = await prisma.keyword.count(); + const ruleCount = await prisma.visualStyleRule.count({ + where: { enabled: true }, + }); + const errorCount = await prisma.keywordCloudErrorLog.count({ + where: { + createdAt: { + gte: new Date(Date.now() - 24 * 60 * 60 * 1000), // 最近24小时 + }, + }, + }); + + return NextResponse.json({ + success: true, + status: 'healthy', + stats: { + quarters: quarterCount, + keywords: keywordCount, + activeRules: ruleCount, + recentErrors: errorCount, + }, + timestamp: new Date().toISOString(), + }); + } catch (error) { + console.error('Health check failed:', error); + + return NextResponse.json( + { + success: false, + status: 'unhealthy', + error: error instanceof Error ? error.message : 'Unknown error', + timestamp: new Date().toISOString(), + }, + { status: 503 } + ); + } +}