-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
62 lines (55 loc) · 2.73 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
var express = require('express');
var app = express();
var cors = require('cors');
var compression = require('compression')
function shouldCompress(req, res) {
if (req.headers['x-no-compression']) {
// don't compress responses with this request header
return false
}
// fallback to standard filter function
return compression.filter(req, res)
}
app.use(cors());
app.options('*', cors());
app.use(compression({ filter: shouldCompress }));
app.get('/devices', function (req, res) {
res.json([
{
"site": "",
"meta": {
"type": "fridge",
"name": "LG",
"mac": "FF-FF-FF-FF-FF-FF"
},
"data": {
"BotCompart": ["1512226846306:-6.304237", "1512226847306:-6.865555", "1512226848306:-0.56960964", "1512226849306:-1.5945711", "1512226850306:-0.47416878", "1512226851306:-0.69944096", "1512226852306:-4.337571", "1512226853306:-0.3595457", "1512226854306:-7.1590548", "1512226855306:-1.9408035", "1512226856306:-1.28617", "1512226857306:1.1471682", "1512226858306:-4.458894"],
"TopCompart": ["1512226846306:5.961624", "1512226847306:0.9834105", "1512226848306:9.913411", "1512226849306:9.60568", "1512226850306:6.142419", "1512226851306:3.9789772", "1512226852306:0.17221428", "1512226853306:4.024467", "1512226854306:5.1167397", "1512226855306:3.5408144", "1512226856306:5.227454", "1512226857306:6.2171865", "1512226858306:1.5780908"]
}
}
]);
});
app.get('/devices/:id/data', function (req, res) {
res.json({
"site": "",
"meta": {
"type": "fridge",
"name": "LG",
"mac": "FF-FF-FF-FF-FF-FF"
},
"data": {
"BotCompart": ["1512226846306:-6.304237", "1512226847306:-6.865555", "1512226848306:-0.56960964", "1512226849306:-1.5945711", "1512226850306:-0.47416878", "1512226851306:-0.69944096", "1512226852306:-4.337571", "1512226853306:-0.3595457", "1512226854306:-7.1590548", "1512226855306:-1.9408035", "1512226856306:-1.28617", "1512226857306:1.1471682", "1512226858306:-4.458894"],
"TopCompart": ["1512226846306:5.961624", "1512226847306:0.9834105", "1512226848306:9.913411", "1512226849306:9.60568", "1512226850306:6.142419", "1512226851306:3.9789772", "1512226852306:0.17221428", "1512226853306:4.024467", "1512226854306:5.1167397", "1512226855306:3.5408144", "1512226856306:5.227454", "1512226857306:6.2171865", "1512226858306:1.5780908"]
}
});
});
app.get('/devices/:id/config', function (req, res) {
res.json({
"turnedOn": true,
"collectFreq": 1000,
"sendFreq": 2000
});
});
app.listen(3301, function () {
console.log('server is listening 3301 port');
});