vbenjs / vite-plugin-mock

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

Feature request: support non-JSON requests/responses #16

Closed zmwangx closed 3 years ago

zmwangx commented 3 years ago

I'm trying to mock a third-party API that returns base64-encoded binary data as text/plain. Unfortunately, at the moment parseJson, application/plain and JSON.stringify are hard-coded so that seems impossible.

https://github.com/anncwb/vite-plugin-mock/blob/798c61ddd81b9af782ca870139b4a2a6938d624a/src/createMockServer.ts#L77-L83

Would you consider adding support for arbitrary requests and responses? I have a patch at https://github.com/zmwangx/vite-plugin-mock/commit/48e9564bc931d4c32312f5a913aa206432a3cc1c adding a rawResponse option to MockMethod to achieve this. I can send a PR if you're okay with that approach, but as long as this use case is made possible, anything goes for me. Thanks.

anncwb commented 3 years ago

This is ok, pr is welcome