-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (37 loc) · 1.03 KB
/
index.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
var express = require('express'),
app = express();
function log_body(body) {
if (process.env.LOG_BODY) {
console.log(body);
}
}
function log_headers(req, headers) {
if (process.env.LOG_HEADERS) {
var interested = headers.reduce(function(str, key) {
str += "\n" + key + ": " + req.get(key);
return str;
}, '');
console.log("\n", interested, "\n");
}
}
function body_parser(req, res, next) {
if (!req.is('application/logplex-1')) {
res.send(500, 'invalid');
return;
}
req.logplexLogs = '';
req.setEncoding('utf8');
req.on('data', function (chunk) {
req.logplexLogs += chunk;
});
req.on('end', next);
}
app.use(body_parser);
app.post('/logs', function(req, res) {
log_headers(req, ['Host', 'Con' ,'Content-Type' ,'Logplex-Msg-Count' ,'Logplex-Frame-Id' ,'Logplex-Drain-Token' ,'User-Agent' ,'Content-Length' ,'Connection']);
log_body(req.logplexLogs);
res.send(201);
});
var server = app.listen(3000, function () {
console.log('Listening on port %d', server.address().port);
});