Using bodyParser after a handler that calls next() async will result in the req hanging.
var restify = require('restify'); // version 2.0.4
var server = restify.createServer();
function syncHandler(req, res, next) {
next();
}
function asyncHandler(req, res, next) {
process.nextTick(function() {
next();
});
}
server.use(asyncHandler);
server.use(restify.bodyParser());
server.post("/hello", function(req, res, next){
console.log(req.url, req.params);
res.send(200);
res.end();
});
server.listen(8081);
curl -is --data "hello=world" "http://localhost:8081/hello"
If you change server.use(asyncHandler) to be syncHandler or remove/move bodyParser to the first server.use, the req will succeed; otherwise it will hang forever.
Using bodyParser after a handler that calls next() async will result in the req hanging.
If you change server.use(asyncHandler) to be syncHandler or remove/move bodyParser to the first server.use, the req will succeed; otherwise it will hang forever.