@@ -388,15 +388,14 @@ export class ConfigurableProxy extends EventEmitter {
388388 } ) ;
389389 }
390390
391- proxyOptsForTarget ( target , reqUrl ) {
391+ proxyOptsForTarget ( target ) {
392392 var proxyOptions = { target } ;
393393
394394 if ( target . protocol . startsWith ( "unix" ) ) {
395395 // No need for agents for unix sockets
396396 // No support for https for unix sockets
397397 proxyOptions . secure = false ;
398398 proxyOptions . target . socketPath = decodeURIComponent ( target . host ) ;
399- proxyOptions . target . pathname = ( target . pathname ? target . pathname + "/" : "" ) + reqUrl ;
400399 } else if ( target . protocol . startsWith ( "https" ) ) {
401400 proxyOptions . secure = true ;
402401 proxyOptions . agent = this . httpsAgent ;
@@ -495,17 +494,24 @@ export class ConfigurableProxy extends EventEmitter {
495494 return ;
496495 }
497496 if ( this . errorTarget ) {
498- var urlSpec = new URL ( this . errorTarget ) ;
499497 // error request is $errorTarget/$code?url=$requestUrl
500- urlSpec . searchParams . set ( "url" , req . url ) ;
501- urlSpec . pathname = urlSpec . pathname + code . toString ( ) ;
502- var url = urlSpec . toString ( ) ;
503- this . log . debug ( "Requesting custom error page: %s" , url ) ;
498+ var options = this . proxyOptsForTarget ( new URL ( this . errorTarget ) ) ;
504499
505- var options = this . proxyOptsForTarget ( urlSpec , req . url ) ;
506500 options . method = "GET" ;
507501
508- var errorRequest = ( options . secure ? https : http ) . request ( url , options , ( upstream ) => {
502+ options . target . searchParams . set ( "url" , req . url ) ;
503+ options . target . pathname = options . target . pathname + code . toString ( )
504+
505+ if ( options . target . socketPath ) {
506+ options . target . hostname = 'localhost'
507+ var url = options . target . toString ( ) . substring ( 5 ) // chop off unix+
508+ } else {
509+ var url = options . target . toString ( )
510+ }
511+
512+ this . log . debug ( "Requesting custom error page: %s" , url ) ;
513+
514+ var errorRequest = ( options . secure ? https : http ) . request ( url , options . target , ( upstream ) => {
509515 if ( res . writableEnded ) {
510516 // response already done
511517 // make sure to consume upstream;
@@ -588,7 +594,7 @@ export class ConfigurableProxy extends EventEmitter {
588594 }
589595
590596 target = new URL ( target ) ;
591- var proxyOptions = this . proxyOptsForTarget ( target , req . url ) ;
597+ var proxyOptions = this . proxyOptsForTarget ( target ) ;
592598
593599 args . push ( proxyOptions ) ;
594600
0 commit comments