File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -44,19 +44,30 @@ export const loggerPlugin: Plugin = (proxyServer, options) => {
4444    const  originalUrl  =  req . originalUrl  ??  `${ req . baseUrl  ||  '' } ${ req . url }  ` ; 
4545
4646    // construct targetUrl 
47-     const   port   =   getPort ( proxyRes . req ?. agent ?. sockets ) ; 
47+     let   target :  URL ; 
4848
49-     const  obj  =  { 
50-       protocol : proxyRes . req . protocol , 
51-       host : proxyRes . req . host , 
52-       pathname : proxyRes . req . path , 
53-     }  as  URL ; 
49+     try  { 
50+       const  port  =  getPort ( proxyRes . req ?. agent ?. sockets ) ; 
5451
55-     const  target  =  new  URL ( `${ obj . protocol }  //${ obj . host } ${ obj . pathname }  ` ) ; 
52+       const  obj  =  { 
53+         protocol : proxyRes . req . protocol , 
54+         host : proxyRes . req . host , 
55+         pathname : proxyRes . req . path , 
56+       }  as  URL ; 
5657
57-     if  ( port )  { 
58-       target . port  =  port ; 
58+       target  =  new  URL ( `${ obj . protocol }  //${ obj . host } ${ obj . pathname }  ` ) ; 
59+ 
60+       if  ( port )  { 
61+         target . port  =  port ; 
62+       } 
63+       // eslint-disable-next-line @typescript-eslint/no-unused-vars 
64+     }  catch  ( err )  { 
65+       // nock issue (https://github.com/chimurai/http-proxy-middleware/issues/1035) 
66+       // fallback to old implementation (less correct - without port) 
67+       target  =  new  URL ( options . target  as  URL ) ; 
68+       target . pathname  =  proxyRes . req . path ; 
5969    } 
70+ 
6071    const  targetUrl  =  target . toString ( ) ; 
6172
6273    const  exchange  =  `[HPM] ${ req . method }   ${ originalUrl }   -> ${ targetUrl }   [${ proxyRes . statusCode }  ]` ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments