@@ -391,15 +391,6 @@ paths:
391
391
const app = new Application ( ) ;
392
392
app . component ( RestComponent ) ;
393
393
const server = await app . getServer ( RestServer ) ;
394
- const greetSpec = {
395
- responses : {
396
- 200 : {
397
- schema : { type : 'string' } ,
398
- description : 'greeting of the day' ,
399
- } ,
400
- } ,
401
- } ;
402
- server . route ( new Route ( 'get' , '/greet' , greetSpec , function greet ( ) { } ) ) ;
403
394
404
395
const response = await createClientForHandler ( server . requestHandler )
405
396
. get ( '/swagger-ui' )
@@ -416,6 +407,45 @@ paths:
416
407
expect ( response . get ( 'Location' ) ) . match ( expectedUrl ) ;
417
408
} ) ;
418
409
410
+ it ( 'honors "x-forwarded-host" headers' , async ( ) => {
411
+ const app = new Application ( ) ;
412
+ app . component ( RestComponent ) ;
413
+ const server = await app . getServer ( RestServer ) ;
414
+
415
+ const response = await createClientForHandler ( server . requestHandler )
416
+ . get ( '/swagger-ui' )
417
+ . set ( 'x-forwarded-proto' , 'http' )
418
+ . set ( 'x-forwarded-host' , 'example.com:8080,my.example.com:9080' ) ;
419
+ await server . get ( RestBindings . PORT ) ;
420
+ const expectedUrl = new RegExp (
421
+ [
422
+ 'https://loopback.io/api-explorer' ,
423
+ '\\?url=http://example.com:8080/openapi.json' ,
424
+ ] . join ( '' ) ,
425
+ ) ;
426
+ expect ( response . get ( 'Location' ) ) . match ( expectedUrl ) ;
427
+ } ) ;
428
+
429
+ it ( 'skips port if it is the default for http or https' , async ( ) => {
430
+ const app = new Application ( ) ;
431
+ app . component ( RestComponent ) ;
432
+ const server = await app . getServer ( RestServer ) ;
433
+
434
+ const response = await createClientForHandler ( server . requestHandler )
435
+ . get ( '/swagger-ui' )
436
+ . set ( 'x-forwarded-proto' , 'https' )
437
+ . set ( 'x-forwarded-host' , 'example.com' )
438
+ . set ( 'x-forwarded-port' , '443' ) ;
439
+ await server . get ( RestBindings . PORT ) ;
440
+ const expectedUrl = new RegExp (
441
+ [
442
+ 'https://loopback.io/api-explorer' ,
443
+ '\\?url=https://example.com/openapi.json' ,
444
+ ] . join ( '' ) ,
445
+ ) ;
446
+ expect ( response . get ( 'Location' ) ) . match ( expectedUrl ) ;
447
+ } ) ;
448
+
419
449
it ( 'exposes "GET /swagger-ui" endpoint with apiExplorer.url' , async ( ) => {
420
450
const server = await givenAServer ( {
421
451
rest : {
0 commit comments