I am working on a Flatiron Union-based app, and it seems that the simple logger I am developing logs before the routes are run, so it does not accurately report what happened. I took the logger sample code from the Union examples. Here’s a stripped down code sample:
var
union = require('union')
, server;
server = union.createServer({
before: [ function (req,res) {
console.log('before');
res.writeHead(404, {"Content-Type": "text/plain"});
res.end("Hello World");
} ],
after: [
function LoggerStream() {
var stream = new union.ResponseStream();
stream.once("pipe", function (req) {
console.log({res: this.res.statusCode, method: this.req.method});
});
return stream;
}
]
});
server.listen(8800);
console.log('union running on 8800');
Here’s what appears in my console:
$ DEBUG=* node ./union.js
union running on 8800
{ res: 200, method: 'GET' }
before
Note that the reported status is 200 when the http server actually returned a 404.
Why is this running out of order?
Here’s a recent reply to your question from our mailing list by indexzero:
If you have more questions, you can find us on github, irc (#nodejitsu on freenode) and our mailing list at flatironjs@googlegroups.com . 🙂