-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 1020 Bytes
/
server.js
File metadata and controls
29 lines (24 loc) · 1020 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
const express = require('express');
const next = require('next');
const http = require('http');
const { rpsSocket } = require('./src/sockets/rpsSocket');
const { tictactoeSocket } = require('./src/sockets/tictactoeSocket');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
const port = process.env.PORT || 3000;
app.prepare().then(() => {
const server = express();
const httpServer = http.createServer(server);
// ساخت یک socket server واحد برای همه بازیها
rpsSocket(httpServer); // این io رو میسازه و export میکنه
const { io, onlineUsers } = require('./src/sockets/rpsSocket');
tictactoeSocket(httpServer, io, onlineUsers); // از همون io و onlineUsers استفاده میکنه
server.all('*', (req, res) => {
return handle(req, res);
});
httpServer.listen(port, (err) => {
if (err) throw err;
console.log(`🚀 server running in port ${port}`);
});
});