mswjs / http-middleware

Spawn an HTTP server from your request handlers or apply them to an existing server using a middleware.
https://npm.im/@mswjs/http-middleware
107 stars 13 forks source link

Incoming request body has been parsed as [object Object] #17

Closed MysticEyeBlink closed 2 years ago

MysticEyeBlink commented 2 years ago

Making POST request with JSON body, to mocked endpoint, produces body value as [object Object]. The cause of this lays on using express.json() and then non-stringified JSON is changed to ArrayBuffer in createMiddleware.

Parsing text to JSON: https://github.com/mswjs/http-middleware/blob/ca849760dd3e32e990d33d66d393c101e5dc1f02/src/server.ts#L8

Encoding non-stringified JSON: https://github.com/mswjs/http-middleware/blob/ca849760dd3e32e990d33d66d393c101e5dc1f02/src/middleware.ts#L22

kettanaito commented 2 years ago

Released: v0.5.1 🎉

This has been released in v0.5.1!

Make sure to always update to the latest version (npm i @mswjs/http-middleware@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.