-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (29 loc) · 1.09 KB
/
server.js
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
const dotenv = require('dotenv');
const { app, server } = require('./app');
const logger = require('./utils/logger');
// Load environment variables
dotenv.config();
// Load environment-specific configurations
const environment = process.env.NODE_ENV || 'development';
logger.info(`Running in ${environment} mode`);
// Check if the application is running inside Docker
const isDocker = process.env.IS_DOCKER || false;
// Load custom configurations based on the environment
const config = require(`./config/env.${environment}.js`);
// Apply any additional environment-specific settings if needed
const PORT = process.env.PORT || config.port || 3000;
const HOST = isDocker ? '0.0.0.0' : config.host || 'localhost';
// Listen on the specified port
server.listen(PORT, HOST, () => {
logger.info(`Server is running at http://${HOST}:${PORT}`);
});
// Graceful shutdown handling
const shutdown = () => {
logger.info('Shutting down server...');
server.close(() => {
logger.info('Server closed.');
process.exit(0);
});
};
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);