forwardemail / forwardemail/supertest
Raw Body is undefined in Supertest.
- Dominant language
- JavaScript
- Stars
- 14.4k
- Forks
- 782
- PR merge metrics
- No merged PRs in 30d
Description
In my Express application I need to access the body of a post-request in the form of the raw buffer as well as the parsed JSON.
In order to do that I use a small middleware like this:
```
// attach raw data of req.body before it gets overwritten by bodyParser
app.use((req, res, next) => {
console.log(req.body); // undefined
req.rawBody = req.body;
next();
});
```
This works well when testing the app via postman, however when the AUT is run it with `supertest` then `req.body` is `undefined` until it hits the `bodyparser` middleware.
Here is my test request:
```
const apiCall = await request(app)
.post('/.netlify/functions/index/api/v1/release')
.send({
'id': 1,
'name': 'Mike'
})
.set('Content-Type', 'application/json');
```
Contributor guide
Assessment
This issue has not been assessed yet.