Skip to content

Instantly share code, notes, and snippets.

@spasiu
Created June 11, 2015 00:29
Show Gist options
  • Save spasiu/f6bb98ce9217f4309bac to your computer and use it in GitHub Desktop.
Save spasiu/f6bb98ce9217f4309bac to your computer and use it in GitHub Desktop.
middleware to attach raw request body, as a promise, to express request
function attachRawBody(req, res, next) {
var body = '';
req.rawBody = Q.defer();
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
req.rawBody.resolve(body);
});
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment