@@ -354,6 +354,14 @@ describe('prefix-based routing', () => {
354
354
) ;
355
355
} ) ;
356
356
357
+ it ( 'does not return alternate links when redirecting' , ( ) => {
358
+ const response = middleware (
359
+ createMockRequest ( '/en' , 'en' , 'http://localhost:3000' , 'de' )
360
+ ) ;
361
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
362
+ expect ( response . headers . get ( 'link' ) ) . toBe ( null ) ;
363
+ } ) ;
364
+
357
365
it ( 'sets a cookie when changing to the default locale' , ( ) => {
358
366
const response = middleware (
359
367
createMockRequest ( '/en' , 'en' , undefined , 'de' )
@@ -3002,7 +3010,7 @@ describe('domain-based routing', () => {
3002
3010
] ) ;
3003
3011
expect (
3004
3012
getLinks (
3005
- createMockRequest ( '/a-propos' , 'fr' , 'http://ca.example.com' )
3013
+ createMockRequest ( '/fr/ a-propos' , 'fr' , 'http://ca.example.com' )
3006
3014
)
3007
3015
) . toEqual ( [
3008
3016
'<http://en.example.com/about>; rel="alternate"; hreflang="en"' ,
@@ -3045,7 +3053,7 @@ describe('domain-based routing', () => {
3045
3053
expect (
3046
3054
getLinks (
3047
3055
createMockRequest (
3048
- '/fr/ produits/apparel/t-shirts' ,
3056
+ '/produits/apparel/t-shirts' ,
3049
3057
'fr' ,
3050
3058
'http://fr.example.com'
3051
3059
)
@@ -3246,23 +3254,23 @@ describe('domain-based routing', () => {
3246
3254
?. split ( ', ' ) ;
3247
3255
}
3248
3256
3249
- [ '/en ' , '/uk' ] . forEach ( ( pathname ) => {
3257
+ [ '/' , '/uk' ] . forEach ( ( pathname ) => {
3250
3258
expect ( getLinks ( createMockRequest ( pathname ) ) ) . toEqual ( [
3251
3259
'<http://localhost:3000/>; rel="alternate"; hreflang="en"' ,
3252
3260
'<http://localhost:3000/uk>; rel="alternate"; hreflang="en-gb"' ,
3253
3261
'<http://localhost:3000/>; rel="alternate"; hreflang="x-default"'
3254
3262
] ) ;
3255
3263
} ) ;
3256
3264
3257
- [ '/en/ about' , '/uk/about' ] . forEach ( ( pathname ) => {
3265
+ [ '/about' , '/uk/about' ] . forEach ( ( pathname ) => {
3258
3266
expect ( getLinks ( createMockRequest ( pathname ) ) ) . toEqual ( [
3259
3267
'<http://localhost:3000/about>; rel="alternate"; hreflang="en"' ,
3260
3268
'<http://localhost:3000/uk/about>; rel="alternate"; hreflang="en-gb"' ,
3261
3269
'<http://localhost:3000/about>; rel="alternate"; hreflang="x-default"'
3262
3270
] ) ;
3263
3271
} ) ;
3264
3272
3265
- expect ( getLinks ( createMockRequest ( '/en/ unknown' ) ) ) . toEqual ( [
3273
+ expect ( getLinks ( createMockRequest ( '/unknown' ) ) ) . toEqual ( [
3266
3274
'<http://localhost:3000/unknown>; rel="alternate"; hreflang="en"' ,
3267
3275
'<http://localhost:3000/uk/unknown>; rel="alternate"; hreflang="en-gb"' ,
3268
3276
'<http://localhost:3000/unknown>; rel="alternate"; hreflang="x-default"'
@@ -3374,6 +3382,39 @@ describe('domain-based routing', () => {
3374
3382
) ;
3375
3383
} ) ;
3376
3384
3385
+ it ( 'keeps the port when there is a x-forwarded-host' , ( ) => {
3386
+ createMiddleware ( {
3387
+ defaultLocale : 'en' ,
3388
+ locales : [ 'en' , 'es' ] ,
3389
+ domains : [
3390
+ {
3391
+ domain : 'localhost:3000' ,
3392
+ defaultLocale : 'en' ,
3393
+ locales : [ 'en' ]
3394
+ } ,
3395
+ {
3396
+ domain : 'localhost:3001' ,
3397
+ defaultLocale : 'es' ,
3398
+ locales : [ 'es' ]
3399
+ }
3400
+ ]
3401
+ } ) (
3402
+ createMockRequest (
3403
+ '/en' ,
3404
+ undefined ,
3405
+ 'http://localhost:3001' ,
3406
+ undefined ,
3407
+ {
3408
+ 'x-forwarded-host' : 'localhost:3001'
3409
+ }
3410
+ )
3411
+ ) ;
3412
+
3413
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
3414
+ 'http://localhost:3000/en'
3415
+ ) ;
3416
+ } ) ;
3417
+
3377
3418
describe ( 'base path' , ( ) => {
3378
3419
it ( 'redirects non-prefixed requests for the default locale' , ( ) => {
3379
3420
middleware (
0 commit comments