azure-function-express icon indicating copy to clipboard operation
azure-function-express copied to clipboard

Http body already parsed

Open runceel opened this issue 7 years ago • 4 comments

Thank you for your great product!! I love it. :)

I found a compatibility issue between pure-express and azure-function-express.

In pure-express, the request body is not parsed. It is raw data. In azure-function-express, the request body is already parsed. It is object.

My workaround is as below:

app.post('path', 
  (req, res, next) => { req.body = req.rawBody; next(); },
  otherMiddlewares,
  (req, res) => {
    // do something
  });

I couldn't use bodyParser module on azure-function-express.

runceel avatar Sep 09 '18 09:09 runceel

What version of azure-function-express are you using?

yvele avatar Sep 09 '18 19:09 yvele

Oh, sorry. I'm using azure-function-express v2.0.0 on Azure Functions v2.

runceel avatar Sep 09 '18 21:09 runceel

Sorry, I taked mistake during write this issue.

A module that I tried is clova-cek-sdk-nodejs. https://github.com/line/clova-cek-sdk-nodejs

Because the module expect the type of req.body is string or Buffer or parseable by body-parser, I did a workaround previous wrote. https://github.com/line/clova-cek-sdk-nodejs/blob/master/src/verifierMiddleware.ts#L24

However, body-parser expect a req is behave like stream. https://github.com/stream-utils/raw-body/blob/master/index.js#L190

Because the IncomingMessage that you provide is not behave like stream, then become to no response.

runceel avatar Sep 10 '18 04:09 runceel

This appears to be a duplicate of #15 where the req object isn't a stream.

I opened a PR which changes the IncomingMessage (wrapped req object) to be a Readable stream with the rawBody pushed. This seems to fix this issue

dcollien avatar Mar 06 '19 10:03 dcollien