-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·92 lines (80 loc) · 2.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var express = require('express');
var fs = require('fs');
var cors = require('cors');
var app = express();
var publicPath = '/public';
var PORT = 3001;
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max + 1);
return Math.floor(Math.random() * (max - min)) + min;
}
app.use(cors());
app.use(express.static(__dirname + publicPath));
app.get("/api/version", function(req, res){
res.json({ version: '0.0.1' });
});
app.get("/api/etl", function(req, res) {
const result = [];
const rowsCount = getRandomInt(5, 30);
for (var i = 0; i < rowsCount; i++) {
result.push({
name: 'Process #' + (i + 1),
isWork: [true, false][getRandomInt(0, 1)],
isError: [true, false][getRandomInt(0, 1)],
lastStartDate: '2018-' + getRandomInt(1, 12) + '-' + getRandomInt(1, 25),
lastErrorDate: '2018-' + getRandomInt(1, 12) + '-' + getRandomInt(1, 25),
lastErrorMessage: ['Some error', 'WTF', 'ERROR CODE 24'][getRandomInt(0, 2)],
});
}
res.json({ "data": result });
});
app.get("/api/hosts", function(req, res) {
const result = [];
const rowsCount = getRandomInt(3, 5);
for (var i = 0; i < rowsCount; i++) {
result.push({
name: 'Host #' + (i + 1),
cpu: Math.random().toFixed(2),
memory: Math.random().toFixed(2),
freeDiskSpace: getRandomInt(0, 128),
fullDiskSpace: ['512', '256', '128'][getRandomInt(0, 2)],
});
}
result.push({
name: 'Host #' + (rowsCount + 1),
cpu: 0.9,
memory: 0.2,
freeDiskSpace: getRandomInt(0, 128),
fullDiskSpace: ['512', '256', '128'][getRandomInt(0, 2)],
});
res.json({ "data": result });
});
app.get("/api/services", function(req, res) {
const result = [];
const rowsCount = getRandomInt(5, 30);
for (var i = 0; i < rowsCount; i++) {
result.push({
name: 'Service #' + (i + 1),
tags: ['tag1', 'tag2', 'tag3', 'tag4', 'tag5'].slice(0, getRandomInt(1, 5)),
status: ['Active', 'Paused', 'Inactive'][getRandomInt(0, 2)],
releaseVersion: ['1.0.0', '1.1.0', '1.1.0-alpha'][getRandomInt(0, 2)],
});
}
res.json({ "data": result });
});
app.get("/api*", function(req, res){
res.status(404).send('<h1>404 Not Found</h1>');
});
app.use(function(req, res) {
var content = fs.readFileSync(__dirname + publicPath + '/index.html', 'utf8');
res.send(content);
});
app.listen(PORT, function(err) {
if (!err) {
console.log('**********************************');
console.log('**** Server is listening on ****');
console.log('**** http://localhost:3001/ ****');
console.log('**********************************');
}
});