-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (31 loc) · 1.14 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
const http = require('http');
const finalhandler = require('finalhandler');
const serveStatic = require('serve-static');
const url = require('url');
var staticHandler = serveStatic('./front/dist');
const server = http.createServer((req, res) => {
if(req.headers['x-forwarded-proto']!='https') {
// Redirect to https
res.writeHead(302, {
'Location': `https://${req.headers.host}${req.url}`
});
res.end();
} else {
staticHandler(req, res, finalhandler(req, res));
}
});
const io = require('socket.io')(server);
io.on('connection', client => {
client.on('clap', unsafedata => {
if ('clipx' in unsafedata && 'clipy' in unsafedata) {
const safedata = {
clipx: Math.min(1, Math.max(0, parseFloat(unsafedata.clipx))),
clipy: Math.min(1, Math.max(0, parseFloat(unsafedata.clipy))),
};
console.log(new Date().toUTCString(), safedata)
client.broadcast.emit('clap', safedata);
}
});
client.on('disconnect', () => { console.log("disconnect"); });
});
server.listen(process.env.PORT || 3000, "0.0.0.0");