-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·36 lines (28 loc) · 886 Bytes
/
server.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 bodyParser = require("body-parser");
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
//Body-Parser Middlware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//Cross Origin Resource Sharing
let cors = require('cors');
app.use(cors({credentials: true, origin: "*"}));
app.use(express.static('Client/build'));
io.on('connection', (socket) => {
console.log("Connected");
socket.on('mousedown', (data) => {
io.emit('mousedown',data);
});
socket.on('mousemove', (data) => {
io.emit('mousemove',data);
});
socket.on('mouseup', (data) => {
io.emit('mouseup',data);
});
});
const port = process.env.PORT || 8080;
server.listen(port, function() {
console.log("Server listening at port", port);
});