-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (27 loc) · 883 Bytes
/
server.js
File metadata and controls
33 lines (27 loc) · 883 Bytes
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
const http = require("http");
const next = require("next");
const { Server } = require("socket.io");
const { registerGameHandlers } = require("./socket/game-server");
const dev = process.env.NODE_ENV !== "production";
const hostname = process.env.HOST || "0.0.0.0";
const port = Number(process.env.PORT || 3000);
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
app
.prepare()
.then(() => {
const httpServer = http.createServer((req, res) => handle(req, res));
const io = new Server(httpServer, {
cors: {
origin: "*",
},
});
registerGameHandlers(io);
httpServer.listen(port, hostname, () => {
console.log(`> Kniffel Server bereit auf http://${hostname}:${port}`);
});
})
.catch((error) => {
console.error("Server konnte nicht gestartet werden:", error);
process.exit(1);
});