mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 18: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
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
// Enhanced Prisma client setup with connection pooling
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { createEnhancedPrismaClient } from "./database-pool";
|
|
import { env } from "./env";
|
|
|
|
// Add prisma to the NodeJS global type
|
|
declare const global: {
|
|
prisma: PrismaClient | undefined;
|
|
};
|
|
|
|
// Connection pooling configuration
|
|
const createPrismaClient = () => {
|
|
// Use enhanced pooling in production or when explicitly enabled
|
|
const useEnhancedPooling =
|
|
process.env.NODE_ENV === "production" ||
|
|
process.env.USE_ENHANCED_POOLING === "true";
|
|
|
|
if (useEnhancedPooling) {
|
|
console.log("Using enhanced database connection pooling with PG adapter");
|
|
return createEnhancedPrismaClient();
|
|
}
|
|
|
|
// Default Prisma client with basic configuration
|
|
return new PrismaClient({
|
|
log:
|
|
process.env.NODE_ENV === "development"
|
|
? ["query", "error", "warn"]
|
|
: ["error"],
|
|
datasources: {
|
|
db: {
|
|
url: env.DATABASE_URL,
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
// Initialize Prisma Client with singleton pattern
|
|
const prisma = global.prisma || createPrismaClient();
|
|
|
|
// Save in global if we're in development to prevent multiple instances
|
|
if (process.env.NODE_ENV !== "production") {
|
|
global.prisma = prisma;
|
|
}
|
|
|
|
// Graceful shutdown handling
|
|
const gracefulShutdown = async () => {
|
|
console.log("Gracefully disconnecting from database...");
|
|
await prisma.$disconnect();
|
|
process.exit(0);
|
|
};
|
|
|
|
// Handle process termination signals
|
|
process.on("SIGINT", gracefulShutdown);
|
|
process.on("SIGTERM", gracefulShutdown);
|
|
|
|
// Connection health check
|
|
export const checkDatabaseConnection = async (): Promise<boolean> => {
|
|
try {
|
|
await prisma.$queryRaw`SELECT 1`;
|
|
return true;
|
|
} catch (error) {
|
|
console.error("Database connection failed:", error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
export { prisma };
|