@@ -33,6 +33,29 @@ const proxyOptionPathsAsProperties = [
3333 pathRewrite : ( ) => "/index.html" ,
3434 router : ( ) => `http://localhost:${ port3 } ` ,
3535 } ,
36+ {
37+ context : "/send-data" ,
38+ target : `http://localhost:${ port1 } ` ,
39+ pathRewrite : ( path , req , res ) => {
40+ res . end ( "data sent from pathRewrite" ) ;
41+
42+ return path ;
43+ } ,
44+ } ,
45+ {
46+ context : "/async-send-data" ,
47+ target : `http://localhost:${ port1 } ` ,
48+ pathRewrite : async ( path , req , res ) => {
49+ await new Promise ( ( resolve ) => {
50+ setTimeout ( ( ) => {
51+ res . end ( "async data sent from pathRewrite" ) ;
52+ resolve ( ) ;
53+ } , 10 ) ;
54+ } ) ;
55+
56+ return path ;
57+ } ,
58+ } ,
3659] ;
3760
3861const proxyOption = [
@@ -252,6 +275,20 @@ describe("proxy option", () => {
252275 expect ( response . status ) . toBe ( 200 ) ;
253276 expect ( response . text ) . toContain ( "Hello" ) ;
254277 } ) ;
278+
279+ it ( "should allow sending a response directly from pathRewrite" , async ( ) => {
280+ const response = await req . get ( "/send-data" ) ;
281+
282+ expect ( response . status ) . toBe ( 200 ) ;
283+ expect ( response . text ) . toBe ( "data sent from pathRewrite" ) ;
284+ } ) ;
285+
286+ it ( "should wait for an async pathRewrite that sends a response" , async ( ) => {
287+ const response = await req . get ( "/async-send-data" ) ;
288+
289+ expect ( response . status ) . toBe ( 200 ) ;
290+ expect ( response . text ) . toBe ( "async data sent from pathRewrite" ) ;
291+ } ) ;
255292 } ) ;
256293 } ) ;
257294
0 commit comments