vbenjs / vite-plugin-mock

A mock plugin for vite.use mockjs.
MIT License
610 stars 96 forks source link

fix: compatible with post request form data acquisition (#135) #135

Closed supercpq closed 4 months ago

supercpq commented 4 months ago

您好,我在使用您的npm包时发现,当请求头为‘x-www-form-urlencoded’时,无法在response对应的函数中,获取req.body;而请求头为‘application/json’时可以正常使用。于是我查看了您代码中关于获取body的部分(即parseJson),并且做了一些改动以此来兼容表单和json两种格式的情况。我打包自测过了,希望可以采纳。

Hello, I found when using your npm package that when the request header is 'x-www-form-urlencoded', req.body cannot be obtained in the function corresponding to response; and the request header is 'application/json' can be used normally. So I checked the part of your code about getting the body (i.e. parseJson), and made some changes to be compatible with both form and json formats. I packaged it and tested it myself, I hope it can be adopted.