-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (29 loc) · 874 Bytes
/
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
let express = require('express');
let fs = require('fs');
let app = express();
let config = require('./config');
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.get('/', function (req, res) {
fs.readFile(config.log_path, 'UTF8', function(err, data){
let output = [];
let split = data.split("\r\n\r\n");
for(var i = 0; i < split.length - 1; i++){
output.push({id: i, message: split[i]});
}
res.render('index', {alerts: output.reverse()});
});
});
app.get('/api', function (req, res) {
fs.readFile(config.log_path, 'UTF8', function(err, data){
let output = [];
let split = data.split("\r\n\r\n");
for(var i = 0; i < split.length - 1; i++){
output.push({id: i, message: split[i]});
}
res.send(output);
});
});
app.listen(3000, function () {
console.log('Open at Port 3000')
})