-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockBackend.js
71 lines (65 loc) · 2.11 KB
/
mockBackend.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
65
66
67
68
69
70
71
const express = require('express');
const app = express();
const port = 3000;
let currentStation = null;
const ENABLE_FAILURES = true;
const FAILURE_RATE = 0.2;
app.use(express.json());
app.get('/sysinfo', (req, res) => {
const enableTrace = true;
const enableRuntime = true;
const enableCoreId = true;
res.send(
JSON.stringify({
app_state: {
time: Date.now(),
mdns_hostname: 'suntransit-fake.local',
},
software: {
app_version: 'Mock app version',
idf_version: 'Mock IDF version',
project_name: 'Mock project name',
compile_time: 'Mock compile time',
compile_date: 'Mock compile date',
},
hardware: {
mac_address: '1A:2B:3C:4D:5E:6F',
chip_model: 1,
},
memory: {
free_heap: 123456,
minimum_free_heap: 123456,
},
...(enableTrace
? {
tasks: [...Array(10)].map((_, index) => ({
name: `TaskNumber${index}`,
priority: index,
state: Math.floor(Math.random() * 6),
stack_high_water_mark: Math.floor(Math.random() * 10000),
runtime: enableRuntime ? Math.floor(Math.random() * 100) : null,
core_id: enableCoreId ? Math.floor(Math.random() * 2) : null,
})),
}
: null),
})
);
});
app.get('/currentstation', (req, res) => {
if (ENABLE_FAILURES && Math.random() < FAILURE_RATE) {
res.status(500).send();
} else {
res.send(JSON.stringify(currentStation));
}
});
app.post('/currentstation', (req, res) => {
if (ENABLE_FAILURES && Math.random() < FAILURE_RATE) {
res.status(500).send();
} else {
currentStation = req.body;
res.send();
}
});
app.listen(port, () => {
console.log(`Mock backend server listening on port ${port}`);
});