mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 15:32:10 +01:00
Security Enhancements: - Implemented proper rate limiting with automatic cleanup for /register and /forgot-password endpoints - Added memory usage protection with MAX_ENTRIES limit (10000) - Fixed rate limiter memory leaks by adding cleanup intervals - Improved IP extraction with x-real-ip and x-client-ip header support Code Quality Improvements: - Refactored ProcessingStatusManager from individual functions to class-based architecture - Maintained backward compatibility with singleton instance pattern - Fixed TypeScript strict mode violations across the codebase - Resolved all build errors and type mismatches UI Component Fixes: - Removed unused chart components (Charts.tsx, DonutChart.tsx) - Fixed calendar component type issues by removing unused custom implementations - Resolved theme provider type imports - Fixed confetti component default options handling - Corrected pointer component coordinate type definitions Type System Improvements: - Extended NextAuth types to support dual auth systems (regular and platform users) - Fixed nullable type handling throughout the codebase - Resolved Prisma JSON field type compatibility issues - Corrected SessionMessage and ImportRecord interface definitions - Fixed ES2015 iteration compatibility issues Database & Performance: - Updated database pool configuration for Prisma adapter compatibility - Fixed pagination response structure in user management endpoints - Improved error handling with proper error class usage Testing & Build: - All TypeScript compilation errors resolved - ESLint warnings remain but no errors - Build completes successfully with proper static generation
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
// Database connection health monitoring endpoint
|
|
import { type NextRequest, NextResponse } from "next/server";
|
|
import { checkDatabaseConnection, prisma } from "@/lib/prisma";
|
|
|
|
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 total AI requests
|
|
prisma.aIProcessingRequest.count(),
|
|
]);
|
|
|
|
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 }
|
|
);
|
|
}
|
|
}
|