-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
41 lines (33 loc) · 1.21 KB
/
main.js
File metadata and controls
41 lines (33 loc) · 1.21 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
const app = require('./src/app');
const dotenv = require('dotenv');
dotenv.config();
const host = process.env.APP_IP || '0.0.0.0';
const PORT = process.env.PORT || 3000;
const server = app.listen(PORT, host, () => {
console.log(`Server running on http://${host}:${PORT}`);
});
// Graceful shutdown handlers
const shutdown = async (signal) => {
console.log(`\n${signal} получен. Начинаем graceful shutdown...`);
// Останавливаем прием новых запросов
server.close(() => {
console.log('✅ HTTP сервер закрыт');
});
// Закрываем соединения с БД
if (app.gracefulShutdown) {
await app.gracefulShutdown();
} else {
process.exit(0);
}
};
// Обработка сигналов для graceful shutdown
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));
// Обработка необработанных ошибок
process.on('unhandledRejection', (reason, promise) => {
console.error('❌ Unhandled Rejection at:', promise, 'reason:', reason);
});
process.on('uncaughtException', (error) => {
console.error('❌ Uncaught Exception:', error);
shutdown('uncaughtException');
});