File tree 1 file changed +20
-9
lines changed
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) => {
44
44
const originalUrl = req . originalUrl ?? `${ req . baseUrl || '' } ${ req . url } ` ;
45
45
46
46
// construct targetUrl
47
- const port = getPort ( proxyRes . req ?. agent ?. sockets ) ;
47
+ let target : URL ;
48
48
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 ) ;
54
51
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 ;
56
57
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 ;
59
69
}
70
+
60
71
const targetUrl = target . toString ( ) ;
61
72
62
73
const exchange = `[HPM] ${ req . method } ${ originalUrl } -> ${ targetUrl } [${ proxyRes . statusCode } ]` ;
You can’t perform that action at this time.
0 commit comments