-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (60 loc) · 1.66 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
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const app = express();
var { generateConnectionTimelineByReportData, generateConnectionTimelineByIHData} = require('./dataUtil')
const cors = require('cors');
let cachedReportData = new Map();
let cachedIHData = new Map();
app.use(cors());
app.get('/', (req, res) => {
res.send('Hello World!\n');
});
app.listen(2000, () => {
console.log('Example app listening on port 2000!');
});
app.get("/getReportData", async (req, res, next) => {
let shop = req.param("shop");
console.log("GET request /getReportData shop : " + shop)
if (shop == undefined) {
//default to TOAL data
shop = "TOTAL"
}
var sendData;
if (cachedReportData.has(shop)) {
//console.log("Use cached data")
sendData = cachedReportData.get(shop)
}
else {
console.log("Generate data")
sendData = await generateConnectionTimelineByReportData(shop)
}
cachedReportData.set(shop, sendData)
let resData = JSON.stringify([...sendData])
let parsedData = JSON.parse(resData);
res.json(parsedData);
});
app.get("/getIHData", async (req, res, next) => {
let shop = req.param("shop");
console.log("GET request /getIHData shop : " + shop)
if (shop == undefined) {
//default to TOAL data
shop = "TOTAL"
}
var sendData;
if (cachedIHData.has(shop)) {
//console.log("Use cached data")
sendData = cachedIHData.get(shop)
}
else {
console.log("Generate data")
sendData = await generateConnectionTimelineByIHData(shop)
}
if(sendData) {
cachedIHData.set(shop, sendData)
let resData = JSON.stringify([...sendData])
let parsedData = JSON.parse(resData);
res.json(parsedData);
}
else {
res.send();
}
});