@@ -59,7 +59,7 @@ export async function requestMiddleware(opt: ViteMockOptions) {
5959 } ) ;
6060
6161 if ( matchRequest ) {
62- const { response, timeout, statusCode, url } = matchRequest ;
62+ const { response, rawResponse , timeout, statusCode, url } = matchRequest ;
6363
6464 if ( timeout ) {
6565 await sleep ( timeout ) ;
@@ -74,13 +74,17 @@ export async function requestMiddleware(opt: ViteMockOptions) {
7474 }
7575 }
7676
77- const body = await parseJson ( req ) ;
78- const mockResponse = isFunction ( response )
79- ? response ( { body, query, headers : req . headers } )
80- : response ;
81- res . setHeader ( 'Content-Type' , 'application/json' ) ;
82- res . statusCode = statusCode || 200 ;
83- res . end ( JSON . stringify ( Mock . mock ( mockResponse ) ) ) ;
77+ if ( isFunction ( rawResponse ) ) {
78+ await rawResponse ( req , res ) ;
79+ } else {
80+ const body = await parseJson ( req ) ;
81+ const mockResponse = isFunction ( response )
82+ ? response ( { body, query, headers : req . headers } )
83+ : response ;
84+ res . setHeader ( 'Content-Type' , 'application/json' ) ;
85+ res . statusCode = statusCode || 200 ;
86+ res . end ( JSON . stringify ( Mock . mock ( mockResponse ) ) ) ;
87+ }
8488
8589 logger && loggerOutput ( 'request invoke' , req . url ! ) ;
8690 return ;
0 commit comments