Add tools to monitor and improve the application's overall efficiency
Adds performance monitoring middleware and admin endpoints for health checks. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c5f0c281-8dd8-4846-b452-4a07bcd21062 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/5b8fba2e-7c70-4729-817d-64d4f830b47a.jpg
This commit is contained in:
@@ -65,6 +65,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
app.use(securityMiddleware);
|
||||
app.use(compressionMiddleware);
|
||||
app.use(requestLoggingMiddleware);
|
||||
app.use(performanceOptimizationService.performanceMiddleware);
|
||||
app.use(generalRateLimit);
|
||||
|
||||
// Health check endpoint for production monitoring
|
||||
@@ -128,6 +129,36 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// Performance optimization endpoints
|
||||
app.get('/api/admin/performance-health', authMiddleware, requireRole(['admin']), (req, res) => {
|
||||
try {
|
||||
const healthStatus = performanceOptimizationService.getHealthStatus();
|
||||
res.json(healthStatus);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to get performance health status' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/admin/performance-metrics', authMiddleware, requireRole(['admin']), (req, res) => {
|
||||
try {
|
||||
const timeframe = parseInt(req.query.timeframe as string) || 15;
|
||||
const metrics = performanceOptimizationService.getAverageMetrics(timeframe);
|
||||
const current = performanceOptimizationService.getCurrentMetrics();
|
||||
res.json({ current, average: metrics });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to get performance metrics' });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/admin/optimize-memory', authMiddleware, requireRole(['admin']), (req, res) => {
|
||||
try {
|
||||
performanceOptimizationService.optimizeMemoryUsage();
|
||||
res.json({ status: 'Memory optimization completed' });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to optimize memory' });
|
||||
}
|
||||
});
|
||||
|
||||
// Configure session middleware
|
||||
app.use(session({
|
||||
secret: process.env.SESSION_SECRET || 'your-secret-key',
|
||||
|
||||
Reference in New Issue
Block a user