forked from Deen-Bridge/dnb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (33 loc) · 1.07 KB
/
Copy pathserver.js
File metadata and controls
42 lines (33 loc) · 1.07 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
import app from "./app.js";
import logger from "./src/config/logger.js";
import { initRedis, closeRedis } from "./src/config/redis.js";
const PORT = process.env.PORT || 5000;
// Initialize Redis
initRedis().catch((err) => {
logger.warn(
"⚠️ Redis initialization failed, continuing without cache:",
err.message
);
});
const server = app.listen(PORT, () => {
logger.info(`🚀🕌 DeenBridge API running on port ${PORT}`);
logger.info(`Environment: ${process.env.NODE_ENV}`);
logger.info(`Process ID: ${process.pid}`);
});
// Graceful shutdown
const gracefulShutdown = async (signal) => {
logger.info(`${signal} received. Starting graceful shutdown...`);
server.close(async () => {
logger.info("HTTP server closed");
// Close Redis connection
await closeRedis();
process.exit(0);
});
// Force shutdown after 10 seconds
setTimeout(() => {
logger.error("Forced shutdown after timeout");
process.exit(1);
}, 10000);
};
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
process.on("SIGINT", () => gracefulShutdown("SIGINT"));