forked from aalves08/poker-tool-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (51 loc) · 1.39 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const { createServer } = require('http');
const { Server } = require('socket.io');
// const redis = require('redis');
const cors = require('cors');
const bodyParser = require('body-parser');
const { handleUserConnect, checkRoom } = require('./modules/api');
// express init
const app = express();
// setup cors and body-parser
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const httpServer = createServer(app);
// setup redis
// const redisClient = redis.createClient(6379, '127.0.0.1');
// Connect to redis server
// (async () => {
// await redisClient.connect();
// })();
// redisClient.on('connect', () => {
// console.log('REDIS Connected!');
// const io = new Server(httpServer, {
// cors: {
// origin: 'http://localhost:4000',
// methods: ['GET', 'POST'],
// },
// });
// io.on('connection', (socket) => {
// handleUserConnect(socket, io, redisClient);
// });
// });
// init socketio
const io = new Server(httpServer, {
cors: {
origin: '*',
methods: ['GET', 'POST'],
},
});
io.on('connection', (socket) => {
handleUserConnect(socket, io);
});
// check session id
app.post('/api/checkRoom', (req, res) => {
const { room } = req.body;
const session = checkRoom(room);
res.send(session);
});
httpServer.listen(8080, () => {
console.log('Server is running...');
});