-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (44 loc) · 1.45 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
const express = require('express');
const path = require('path');
const app = express();
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// An api endpoint that returns a short list of items
app.get('/api/events', (req,res) => {
res.writeHead(200, {
Connection: "keep-alive",
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache"
});
setTimeout(() => {
res.write('data: {"flight": "I768", "state": "landing"}');
res.write("\n\n");
}, 3000);
setTimeout(() => {
res.write('data: {"flight": "I768", "state": "landed"}');
res.write("\n\n");
}, 6000);
});
// An api endpoint that returns a short list of items
app.get('/api/eventsOther', (req,res) => {
res.writeHead(200, {
Connection: "keep-alive",
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache"
});
setTimeout(() => {
res.write('data: {"flight": "D654", "state": "landing"}');
res.write("\n\n");
}, 5000);
setTimeout(() => {
res.write('data: {"flight": "D654", "state": "landed"}');
res.write("\n\n");
}, 8000);
});
// Handles any requests that don't match the ones above
app.get('*', (req,res) =>{
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
const port = process.env.PORT || 5000;
app.listen(port);
console.log('App is listening on port ' + port);