mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-02-13 17:35:44 +01:00
- Update tsconfig to ES2024 target and bundler moduleResolution - Add dynamic imports for chart.js and recharts (bundle optimization) - Consolidate 17 useState into useReducer in sessions page - Fix 18 .js extension imports across lib files - Add type declarations for @rapideditor/country-coder - Fix platform user types (PlatformUserRole enum) - Fix Calendar component prop types - Centralize next-auth type augmentation - Add force-dynamic to all API routes (prevent build-time prerender) - Fix Prisma JSON null handling with Prisma.DbNull - Fix various type mismatches (SessionMessage, ImportRecord, etc.) - Export ButtonProps from button component - Update next-themes import path - Replace JSX.Element with React.ReactElement - Remove obsolete debug scripts and pnpm lockfile - Downgrade eslint to v8 for next compatibility
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
// Database connection health monitoring endpoint
|
|
import { type NextRequest, NextResponse } from "next/server";
|
|
import { checkDatabaseConnection, prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// Check if user has admin access (you may want to add proper auth here)
|
|
const authHeader = request.headers.get("authorization");
|
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
// Basic database connectivity check
|
|
const isConnected = await checkDatabaseConnection();
|
|
|
|
if (!isConnected) {
|
|
return NextResponse.json(
|
|
{
|
|
status: "unhealthy",
|
|
database: {
|
|
connected: false,
|
|
error: "Database connection failed",
|
|
},
|
|
timestamp: new Date().toISOString(),
|
|
},
|
|
{ status: 503 }
|
|
);
|
|
}
|
|
|
|
// Get basic metrics
|
|
const metrics = await Promise.allSettled([
|
|
// Count total sessions
|
|
prisma.session.count(),
|
|
// Count processing status records
|
|
prisma.sessionProcessingStatus.count(),
|
|
// Count recent AI requests
|
|
prisma.aIProcessingRequest.count({
|
|
where: {
|
|
requestedAt: {
|
|
gte: new Date(Date.now() - 24 * 60 * 60 * 1000), // Last 24 hours
|
|
},
|
|
},
|
|
}),
|
|
]);
|
|
|
|
const [sessionsResult, statusResult, aiRequestsResult] = metrics;
|
|
|
|
return NextResponse.json({
|
|
status: "healthy",
|
|
database: {
|
|
connected: true,
|
|
connectionType:
|
|
process.env.USE_ENHANCED_POOLING === "true"
|
|
? "enhanced_pooling"
|
|
: "standard",
|
|
},
|
|
metrics: {
|
|
totalSessions:
|
|
sessionsResult.status === "fulfilled"
|
|
? sessionsResult.value
|
|
: "error",
|
|
processingRecords:
|
|
statusResult.status === "fulfilled" ? statusResult.value : "error",
|
|
recentAIRequests:
|
|
aiRequestsResult.status === "fulfilled"
|
|
? aiRequestsResult.value
|
|
: "error",
|
|
},
|
|
environment: {
|
|
nodeEnv: process.env.NODE_ENV,
|
|
enhancedPooling: process.env.USE_ENHANCED_POOLING === "true",
|
|
connectionLimit: process.env.DATABASE_CONNECTION_LIMIT || "default",
|
|
poolTimeout: process.env.DATABASE_POOL_TIMEOUT || "default",
|
|
},
|
|
timestamp: new Date().toISOString(),
|
|
});
|
|
} catch (error) {
|
|
console.error("Database health check failed:", error);
|
|
|
|
return NextResponse.json(
|
|
{
|
|
status: "error",
|
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
timestamp: new Date().toISOString(),
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|