@@ -13,14 +13,18 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
1313
1414describe ( "Proxy Tests" , function ( ) {
1515 var port = 8902 ;
16+ var listenOptions = {
17+ port : port ,
18+ ip : '127.0.0.1'
19+ } ;
1620 var testPort = port + 10 ;
1721 var proxy ;
18- var proxyUrl = "http://127.0.0.1 :" + port ;
22+ var proxyUrl = "http://" + listenOptions . ip + " :" + port ;
1923 var hostTest = "test.localhost.jovyan.org" ;
2024 var hostUrl = "http://" + hostTest + ":" + port ;
2125
2226 beforeEach ( function ( callback ) {
23- util . setupProxy ( port ) . then ( function ( newProxy ) {
27+ util . setupProxy ( listenOptions ) . then ( function ( newProxy ) {
2428 proxy = newProxy ;
2529 callback ( ) ;
2630 } ) ;
@@ -338,10 +342,12 @@ describe("Proxy Tests", function () {
338342 } ) ;
339343
340344 it ( "custom error target" , function ( done ) {
341- var proxyPort = 55550 ;
345+ var listenOptions = {
346+ port : 55550
347+ } ;
342348 util
343- . setupProxy ( proxyPort , { errorTarget : "http://127.0.0.1:55565" } , [ ] )
344- . then ( ( ) => fetch ( "http://127.0.0.1:" + proxyPort + "/foo/bar" ) )
349+ . setupProxy ( listenOptions , { errorTarget : "http://127.0.0.1:55565" } , [ ] )
350+ . then ( ( ) => fetch ( "http://127.0.0.1:" + listenOptions . port + "/foo/bar" ) )
345351 . then ( ( res ) => {
346352 expect ( res . status ) . toEqual ( 404 ) ;
347353 expect ( res . headers . get ( "content-type" ) ) . toEqual ( "text/plain" ) ;
@@ -405,10 +411,12 @@ describe("Proxy Tests", function () {
405411 } ) ;
406412
407413 it ( "backend error" , function ( done ) {
408- var proxyPort = 55550 ;
414+ var listenOptions = {
415+ port : 55550
416+ } ;
409417 util
410- . setupProxy ( proxyPort , { errorTarget : "http://127.0.0.1:55565" } , [ ] )
411- . then ( ( ) => fetch ( "http://127.0.0.1:" + proxyPort + "/%" ) )
418+ . setupProxy ( listenOptions , { errorTarget : "http://127.0.0.1:55565" } , [ ] )
419+ . then ( ( ) => fetch ( "http://127.0.0.1:" + listenOptions . port + "/%" ) )
412420 . then ( ( res ) => {
413421 expect ( res . status ) . toEqual ( 500 ) ;
414422 expect ( res . headers . get ( "content-type" ) ) . toEqual ( "text/plain" ) ;
@@ -433,7 +441,9 @@ describe("Proxy Tests", function () {
433441 } ) ;
434442
435443 it ( "Redirect location with rewriting" , function ( done ) {
436- var proxyPort = 55556 ;
444+ var listenOptions = {
445+ port : 55556
446+ } ;
437447 var options = {
438448 protocolRewrite : "https" ,
439449 autoRewrite : true ,
@@ -442,10 +452,10 @@ describe("Proxy Tests", function () {
442452 // where the backend server redirects us.
443453 // Note that http-proxy requires (logically) the redirection to be to the same (internal) host.
444454 var redirectTo = "https://127.0.0.1:" + testPort + "/whatever" ;
445- var expectedRedirect = "https://127.0.0.1:" + proxyPort + "/whatever" ;
455+ var expectedRedirect = "https://127.0.0.1:" + listenOptions . port + "/whatever" ;
446456
447457 util
448- . setupProxy ( proxyPort , options , [ ] )
458+ . setupProxy ( listenOptions , options , [ ] )
449459 . then ( ( proxy ) =>
450460 util . addTargetRedirecting (
451461 proxy ,
@@ -456,7 +466,7 @@ describe("Proxy Tests", function () {
456466 )
457467 )
458468 . then ( ( ) =>
459- fetch ( "http://127.0.0.1:" + proxyPort + "/external/urlpath/" , { redirect : "manual" } )
469+ fetch ( "http://127.0.0.1:" + listenOptions . port + "/external/urlpath/" , { redirect : "manual" } )
460470 )
461471 . then ( ( res ) => {
462472 expect ( res . status ) . toEqual ( 301 ) ;
@@ -483,8 +493,10 @@ describe("Proxy Tests", function () {
483493 done ( ) ;
484494 return ;
485495 }
486- var proxyPort = 55556 ;
487- var testPort = proxyPort + 20 ;
496+ var listenOptions = {
497+ port : 55556
498+ } ;
499+ var testPort = listenOptions . port + 20 ;
488500 var options = {
489501 clientSsl : {
490502 key : fs . readFileSync ( path . resolve ( __dirname , "ssl/proxy-client/proxy-client.key" ) ) ,
@@ -494,7 +506,7 @@ describe("Proxy Tests", function () {
494506 } ;
495507
496508 util
497- . setupProxy ( proxyPort , options , [ ] )
509+ . setupProxy ( listenOptions , options , [ ] )
498510 . then ( ( proxy ) =>
499511 util . addTarget ( proxy , "/backend/" , testPort , false , null , {
500512 key : fs . readFileSync ( path . resolve ( __dirname , "ssl/backend/backend.key" ) ) ,
@@ -503,7 +515,7 @@ describe("Proxy Tests", function () {
503515 requestCert : true ,
504516 } )
505517 )
506- . then ( ( ) => fetch ( "http://127.0.0.1:" + proxyPort + "/backend/urlpath/" ) )
518+ . then ( ( ) => fetch ( "http://127.0.0.1:" + listenOptions . port + "/backend/urlpath/" ) )
507519 . then ( ( res ) => {
508520 expect ( res . status ) . toEqual ( 200 ) ;
509521 } )
0 commit comments