-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
54 lines (46 loc) · 1.14 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import express from 'express';
import path from 'path';
import socketIO from 'socket.io';
import { Server } from 'http';
import * as predb from './lib/predb';
const app = express(),
server = Server(app),
io = socketIO(server),
host = 'localhost',
port = '3000';
app.use(express.static('public'));
app.get('/', function (req, res) {
res.send(`
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8' />
<title>gaxx</title>
<link rel='stylesheet' href='style.css'>
</head>
<body>
<div id='root'></div>
<script src='bundle.js'></script>
</body>
</html>
`);
});
server.listen(port, () => {
console.log('Listening at http://%s:%s', host, port);
io.on('connection', socket => {
const data = predb.getReleaseCache();
if (data) io.emit('update', data, true);
});
predb.get(err => {
if (err) return console.log(err);
/*
* TODO Handle termination if getNew errors
*/
setInterval(() => {
predb.getNew((err, data) => {
if (err) console.log(err);
if (data) io.emit('update', data, true);
});
}, 10000);
});
});