@@ -330,5 +330,51 @@ describe("Rewriting Domains", function() {
330330 var actual = input . replace ( rewrite . match , bound ) ;
331331 assert . equal ( actual , expected ) ;
332332 } ) ;
333+ it ( "should support proxy: localhost" , function ( ) {
334+ var input = `
335+ <a href="http://localhost:6426">should skip</a>
336+ <a href="http://localhost">should hit</a>
337+ <a href="http://localhost/base.html">should hit (2)</a>
338+ ` ;
339+ var expected = `
340+ <a href="http://localhost:6426">should skip</a>
341+ <a href="//${ proxyUrl } ">should hit</a>
342+ <a href="//${ proxyUrl } /base.html">should hit (2)</a>
343+ ` ;
344+ var rewrite = utils . rewriteLinks (
345+ { hostname : "localhost" } ,
346+ proxyUrl
347+ ) ;
348+ var bound = rewrite . fn . bind (
349+ null ,
350+ { headers : { host : proxyUrl } } ,
351+ { }
352+ ) ;
353+ var actual = input . replace ( rewrite . match , bound ) ;
354+ assert . equal ( actual , expected ) ;
355+ } ) ;
356+ it ( "should support localhost + port" , function ( ) {
357+ var input = `
358+ <a href="http://localhost:6426">should skip</a>
359+ <a href="http://localhost:8080">should hit</a>
360+ <a href="http://localhost:8080/base.html">should hit (2)</a>
361+ ` ;
362+ var expected = `
363+ <a href="http://localhost:6426">should skip</a>
364+ <a href="//${ proxyUrl } ">should hit</a>
365+ <a href="//${ proxyUrl } /base.html">should hit (2)</a>
366+ ` ;
367+ var rewrite = utils . rewriteLinks (
368+ { hostname : "localhost" , port : "8080" } ,
369+ proxyUrl
370+ ) ;
371+ var bound = rewrite . fn . bind (
372+ null ,
373+ { headers : { host : proxyUrl } } ,
374+ { }
375+ ) ;
376+ var actual = input . replace ( rewrite . match , bound ) ;
377+ assert . equal ( actual , expected ) ;
378+ } ) ;
333379 } ) ;
334380} ) ;
0 commit comments