From 269c4a95730836a43732bd85a9bfcaabca15f56a Mon Sep 17 00:00:00 2001 From: Caihaohan Date: Tue, 27 Jan 2026 20:28:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E8=AF=8D=E8=AF=8D=E4=BA=91=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E7=AB=AF=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/keyword-cloud/health/route.ts | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/app/api/keyword-cloud/health/route.ts 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 } + ); + } +}