37 lines
954 B
JavaScript
37 lines
954 B
JavaScript
var app = require('express')();
|
|
var assert = require('assert');
|
|
var http = require('http');
|
|
var through = require('through');
|
|
var logfmt = require('../logfmt');
|
|
|
|
app.use(logfmt.bodyParserStream());
|
|
|
|
app.post('/logs', function(req, res){
|
|
if(!req.body) return res.send('OK');
|
|
|
|
req.body.pipe(through(function(line){
|
|
try {
|
|
console.log(line);
|
|
if(line.at === 'error'){
|
|
assert.equal('H12', line.code)
|
|
assert.equal('50.17.15.69', line.fwd)
|
|
}else{
|
|
assert.equal("bar", line["foo"])
|
|
assert.equal(14, line.a)
|
|
assert.equal("hello kitty", line['baz'])
|
|
assert.equal('bro', line['cool%story'])
|
|
assert.equal(true, line.f)
|
|
assert.equal(true, line['%^asdf'])
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
res.send('FAIL')
|
|
}
|
|
}, end))
|
|
|
|
function end() { res.send('OK') }
|
|
})
|
|
|
|
http.createServer(app).listen(3000);
|
|
console.log("Express server listening on port 3000")
|