-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (39 loc) · 1008 Bytes
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
process.on("uncaughtException", (e) => {
console.log("Uncaught exception::" + e);
console.log("Process is exiting");
process.exit(1);
});
const http = require("http");
const app = require("./src/app");
const {
app: { port },
origin,
} = require("./src/config/config.app");
const server = http.createServer(app);
const io = require("socket.io")(server, {
cors: {
origin: `${origin}`,
},
debug: true,
});
const serverInstance = server.listen(port, () => {
console.log("App start with port::" + port);
});
// init socket server events listeners
require("./src/socket/index")(io);
global._io = io;
process.on("unhandledRejection", (e) => {
console.log("Unhandled rejection::" + e);
console.log("Server is shutting down");
serverInstance.close(() => {
process.exit(1);
});
});
process.on("SIGINT", () => {
console.log("Ctrl c deteted app is closing");
serverInstance.close(() => {
console.log("Server closed");
});
});
module.exports = server;