File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed
packages/vite-plugin-mock Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " vite-plugin-mock" ,
3- "version" : " 3.0.1 " ,
3+ "version" : " 3.0.2 " ,
44 "description" : " A mock plugin for vite" ,
55 "main" : " dist/index.cjs" ,
66 "module" : " dist/index.mjs" ,
Original file line number Diff line number Diff line change @@ -153,23 +153,29 @@ function cleanRequireCache(opt: ViteMockOptions) {
153153
154154function parseJson ( req : IncomingMessage ) : Promise < Recordable > {
155155 return new Promise ( ( resolve ) => {
156- let body = ''
157- let jsonStr = ''
156+ let jsonStr : Recordable = { }
157+ let str = ''
158158 req . on ( 'data' , function ( chunk ) {
159- body += chunk
159+ str += chunk
160160 } )
161- req . on ( 'end' , function ( ) {
161+ req . on ( 'end' , ( ) => {
162162 try {
163- jsonStr = JSON . parse ( body )
164- } catch ( err ) {
165- jsonStr = ''
163+ // json
164+ jsonStr = JSON . parse ( str )
165+ } catch ( e ) {
166+ // x-www-form-urlencoded
167+ const params = new URLSearchParams ( str )
168+ const body : Recordable = { }
169+ params . forEach ( ( value , key ) => {
170+ body [ key ] = value
171+ } )
172+ jsonStr = body
166173 }
167- resolve ( jsonStr as any )
174+ resolve ( jsonStr )
168175 return
169176 } )
170177 } )
171178}
172-
173179// load mock .ts files and watch
174180async function getMockConfig ( opt : ViteMockOptions , config : ResolvedConfig ) {
175181 const { absConfigPath, absMockPath } = getPath ( opt )
You can’t perform that action at this time.
0 commit comments