-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (36 loc) · 1.14 KB
/
server.js
File metadata and controls
46 lines (36 loc) · 1.14 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
const path = require("path");
const express = require("express");
const config = require("./config");
// const connectDB = require('./config/db');
const configureMiddleware = require("./middleware");
const configureRoutes = require("./routes");
const socketio = require("socket.io");
const gameSocket = require("./socket/index");
// Connect and get reference to mongodb instance
// let db;
// (async function () {
// db = await connectDB();
// })();
// Init express app
const app = express();
// Config Express-Middleware
configureMiddleware(app);
// Set-up Routes
configureRoutes(app);
// Start server and listen for connections
const server = app.listen(config.PORT, () => {
console.log(
`Server is running in ${config.NODE_ENV} mode and is listening on port ${config.PORT}...`
);
});
// Handle real-time poker game logic with socket.io
const io = socketio(server);
io.on("connect", (socket) => gameSocket.init(socket, io));
// Error handling - close server
process.on("unhandledRejection", (err) => {
// db.disconnect();
console.error(`Error: ${err.message}`);
server.close(() => {
process.exit(1);
});
});