I need to get the source data for a specific endpoint in a node / express application. I:
app.use('/paypal/ipn',function(req, res, next) {
var postData='';
req.on('data', function(chunk) {
postData += chunk;
});
req.on('end', function() {
req.rawBody = postData;
console.log('ended buffering. result: ' + req.rawBody);
next();
});
});
What happens is that I get console.log output in the console, and then nothing happens. After a minute or so, I see that the server returns 200 - maybe a timeout. This is similar to the next () command, which never executes or never executes or is not put.
When I comment on everything and just call next ():
app.use('/paypal/ipn',function(req, res, next) {
/*
var postData='';
req.on('data', function(chunk) {
postData += chunk;
});
req.on('end', function() {
req.rawBody = postData;
console.log('ended buffering. result: ' + req.rawBody);
next();
});
*/
next();
});
Everything works, that is, the endpoint is called (of course, the request does not contain rawBody).
So it seems like I'm doing something wrong, how am I rawBody buffer? Something that calls next () does not work?