It would seem a jaded question, but in Express 4 I can't do it at all. I need to get a raw POST
request and encrypt it using crypt
. How I tried to do this:
var crypto = require('crypto'); function calculateSignature(key) { return function(req, res, next) { var hash = req.header("TrialPay-HMAC-MD5"), hmac = crypto.createHmac("md5", key); req.on("data", function(data) { console.log("Data is: ", data); hmac.update(data); }); req.on("end", function() { console.log("Called end"); var crypted = hmac.digest("hex"); if(crypted === hash) { // Valid request return res.send("Success!", { "Content-Type": "text/plain" }); } else { // Invalid request return res.send("Invalid TrialPay hash", { "Content-Type": "text/plain" }, 403); } }); req.on("error", function(err) { return next(err); }); } } app.post("/trialpay", calculateSignature("[MY MERCHANT KEY]"));
Bottom line: - Eternal waiting for an answer, nothing in the console. How to get an analog file_get_contents("php://input");
in Express.JS?
bodyParser.raw()
? It even has averify
option. - Alexey Tenapp.use(bodyParser.raw())
, and then how do I get this raw from the request?req.body.toString()
or how? - blitsmiddleware
completely replacesreq.body
. And then I need to spar him. I tried to use it at the beginning of the script usingapp.use(bodyParser.raw());
, but nothing has changed at all, as was the type ofreq.body
Object
, and remained. - blitsreq.body
doesn'treq.body
at all. Apparently you already have some kind of middleware that creates it. I suppose that's why your code doesn't work. - Alexey Ten