forked from nathydre21/nepa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts.backup
More file actions
61 lines (51 loc) · 1.78 KB
/
Copy pathapp.ts.backup
File metadata and controls
61 lines (51 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import express from 'express';
import swaggerUi from 'swagger-ui-express';
import { configureSecurity } from './src/config/security';
import { loggingMiddleware, setupGlobalErrorHandling, logger } from './middleware/logger';
import { swaggerSpec } from './src/config/swagger';
import ConnectionPoolManager from './databases/ConnectionPoolManager';
const app = express();
// Initialize Connection Pool Manager
ConnectionPoolManager.startHealthMonitoring(60000); // Monitor every minute
// Basic middleware setup
app.use(...loggingMiddleware);
configureSecurity(app);
app.use(express.json({ limit: '10kb' }));
// API Documentation
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Health Check
app.get('/health', (req, res) => {
res.status(200).json({
status: 'UP',
timestamp: new Date().toISOString(),
uptime: process.uptime()
});
});
// Connection Pool Management endpoints
app.get('/api/connection-pool/stats', async (req, res) => {
try {
const stats = await ConnectionPoolManager.getAllPoolStats();
res.json(stats);
} catch (error) {
res.status(500).json({ error: 'Failed to get connection pool stats' });
}
});
app.get('/api/connection-pool/health', async (req, res) => {
try {
const healthChecks = await ConnectionPoolManager.getAllHealthChecks();
res.json(healthChecks);
} catch (error) {
res.status(500).json({ error: 'Failed to get connection pool health' });
}
});
app.get('/api/connection-pool/performance', async (req, res) => {
try {
const metrics = await ConnectionPoolManager.getPerformanceMetrics();
res.json(metrics);
} catch (error) {
res.status(500).json({ error: 'Failed to get connection pool performance metrics' });
}
});
// Setup global error handling
setupGlobalErrorHandling(app);
export default app;