-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (38 loc) · 1.2 KB
/
server.js
File metadata and controls
46 lines (38 loc) · 1.2 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
import createApp from './app.js';
import { logger } from './lib/logger.js';
import { setServer } from './lib/graceful-shutdown.js';
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || '0.0.0.0';
async function startServer() {
try {
const app = await createApp();
const server = app.listen(PORT, HOST, () => {
logger.info(`Server running on ${HOST}:${PORT}`);
logger.info(`API Documentation: http://${HOST}:${PORT}/docs`);
logger.info(`Health Check: http://${HOST}:${PORT}/health`);
logger.info(`OpenAPI Spec: http://${HOST}:${PORT}/openapi.json`);
});
setServer(server);
server.on('error', (error) => {
if (error.syscall !== 'listen') {
throw error;
}
switch (error.code) {
case 'EACCES':
logger.error(`Port ${PORT} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
logger.error(`Port ${PORT} is already in use`);
process.exit(1);
break;
default:
throw error;
}
});
} catch (error) {
logger.error('Failed to start server:', error);
process.exit(1);
}
}
startServer();