-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (44 loc) · 1.23 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
48
49
50
51
52
53
54
55
56
57
58
59
//jshint: esversion 6
const serveStatic = require('serve-static');
const express = require('express');
const app = express();
const cors = require('cors');
// app.use(express.static("public"));
// app.get('', (req, res) => {
// res.sendFile("index.html")
// });
app.use(cors());
app.options('*', cors());
var history = require('connect-history-api-fallback');
app.use(history());
app.use(serveStatic(__dirname + '/dist'));
const http = require('http').createServer(app);
const io = require('socket.io')(http, {
cors: {
origin: '*',
methods: ['GET', 'POST']
}
});
io.on('connection', (socket) => {
socket.on('howdy', (message) => {
console.log(message);
});
socket.on('breath', (breath) => {
socket.broadcast.emit('breath', breath);
});
socket.on('bite', (bite) => {
socket.broadcast.emit('bite', bite);
});
socket.on('nod', (nod) => {
socket.broadcast.emit('nod', nod);
});
socket.on('tilt', (tilt) => {
socket.broadcast.emit('tilt', tilt);
});
socket.on('heartbeat', (heartbeat) => {
socket.broadcast.emit('heartbeat', heartbeat);
});
});
http.listen(process.env.PORT || 3000, () => {
console.log('listnin 3K yeet');
});