forwardemail / forwardemail/supertest

Raw Body is undefined in Supertest.

Open
#675 3 comments 10 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.