-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (29 loc) · 938 Bytes
/
server.js
File metadata and controls
32 lines (29 loc) · 938 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
const express = require('express');
const app = express();
const path = require('path'); // for production
const socket = require('socket.io');
if(process.env.NODE_ENV === 'production'){
//set static folder
app.use(express.static('client/build'));
app.get('*',(req,res)=>{
res.sendFile(path.resolve(__dirname,'client','build','index.html'));
});
}
app.set('port', (process.env.PORT || 4000));
const server = app.listen(app.get('port'), () => console.log(`Server is runnig`));
const io = socket(server);
const cors = require('cors');
app.use(cors());
//routes
io.on('connection',socket =>{
console.log(`Connected with ${socket.id}`);
socket.on('englishChat',data => {
io.sockets.emit('englishChat',data);
});
socket.on('gamingChat',data => {
io.sockets.emit('gamingChat',data);
});
socket.on('physicsChat',data => {
io.sockets.emit('physicsChat',data);
});
})