-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (34 loc) · 1002 Bytes
/
index.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
const dotenv = require("dotenv").config(),
config = require("./src/config/config"),
express = require("./src/config/express"),
db = require("./src/config/db"),
version = config.get("version"),
{ createServer } = require("http"),
{ Server } = require("socket.io");
const app = express();
const httpServer = createServer(app);
const io = new Server(httpServer, {
/* options */
cors: {
origin: "*",
},
});
io.on("connection", (socket) => {
console.log(`user ${socket.id} connected`);
});
// Require all new routes here
require("./src/routes/game.route")(app, io);
db.connect(function (err) {
if (err) {
console.log("Unable to connect to MongoDB");
process.exit(1);
} else {
const expressPort = process.env.PORT || 3333;
httpServer.listen(expressPort, function () {
console.log(`API Ver: ${version}; Listening on port: ${expressPort}`);
console.log(
`Connect Via : http://localhost:${expressPort}/api/${version}`
);
});
}
});