我正在开发一个基于 Flatiron Union 的应用程序,似乎我在运行路由之前正在开发日志的简单记录器,所以它不能准确地报告发生了什么。我从 Union 示例中获取了记录器示例代码。这是一个精简的代码示例:
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');
这是我的控制台中显示的内容:
$ DEBUG=* node ./union.js
union running on 8800
{ res: 200, method: 'GET' }
before
请注意,当 http 服务器实际返回 404 时,报告的状态为 200。
为什么会出现这种情况?