-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (38 loc) · 1.21 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
require('dotenv').config();
const process = require('process');
const path = require('path');
const express = require('express');
const http = require('http');
const socket = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socket(server, {
cors: {
origin: '*',
},
transports: ['websocket', 'polling'],
});
const PORT = process.env.PORT || 5000;
io.on('connection', (socket) => {
console.log(`User connected on process ${process.pid}`);
socket.on('canvas-data', (data) => {
console.log('sending data', process.pid);
socket.broadcast.emit('canvas-data', { data: data.data, id: process.pid });
});
socket.on('disconnect', () => {
console.log(`User disconnected from process ${process.pid}`);
});
});
// if (process.env.NODE_ENV === 'production') {
// app.use(express.static(path.join(__dirname, 'client', 'build')));
// app.get('/', (req, res) => {
// res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
// });
// }
app.get('/', (req, res) => {
res.send('Server running!');
});
server.listen(PORT, () => {
console.log(`Listening all instances on port: ${PORT}`);
console.log(`Current instance id: ${process.pid}`);
});