-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 775 Bytes
/
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
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const port = process.env.PORT || 5000;
const io = require('socket.io')(server, {
cors: {
origin: false,
methods: ["GET", "POST"]
}
});
app.use(express.static('client/build'));
io.on('connection', socket => {
console.log("A user connected via " + socket.client.conn.transport.constructor.name + "!");
socket.on('disconnect', () => {
console.log('A user disconnected!');
});
socket.on('chat message', msg => {
io.emit('chat message', msg);
})
});
app.post('/api/world', (req, res) => {
console.log(req.body);
res.send({
message: `Hello World!`,
});
});
server.listen(port, () => console.log(`Listening on port ${port}`));