@@ -20,7 +20,10 @@ import {
20
20
getGlobalObject ,
21
21
checkType ,
22
22
assertUsage ,
23
- normalizeUrlPathname
23
+ normalizeUrlPathname ,
24
+ removeBaseServer ,
25
+ modifyUrlPathname ,
26
+ prependBase
24
27
} from './utils.js'
25
28
import {
26
29
assertNoInfiniteAbortLoop ,
@@ -461,13 +464,18 @@ function normalizePathname(pageContextInit: { urlOriginal: string }) {
461
464
}
462
465
463
466
function getPermanentRedirect ( pageContextInit : { urlOriginal : string } ) {
464
- const { redirects } = getGlobalContext ( )
465
- const urlTarget = resolveRedirects ( redirects , pageContextInit . urlOriginal )
466
- if ( ! urlTarget ) return null
467
- const httpResponse = createHttpResponseObjectRedirect (
468
- { url : urlTarget , statusCode : 301 } ,
469
- pageContextInit . urlOriginal
470
- )
467
+ const { redirects, baseServer } = getGlobalContext ( )
468
+ const urlWithoutBase = removeBaseServer ( pageContextInit . urlOriginal , baseServer )
469
+ let urlPathname : undefined | string
470
+ let urlRedirect = modifyUrlPathname ( urlWithoutBase , ( urlPathname_ ) => {
471
+ urlPathname = urlPathname_
472
+ return resolveRedirects ( redirects , urlPathname )
473
+ } )
474
+ assert ( urlPathname )
475
+ if ( urlRedirect === urlWithoutBase ) return null
476
+ urlRedirect = prependBase ( urlRedirect , baseServer )
477
+ assert ( urlRedirect !== pageContextInit . urlOriginal )
478
+ const httpResponse = createHttpResponseObjectRedirect ( { url : urlRedirect , statusCode : 301 } , urlPathname )
471
479
const pageContextHttpResponse = { ...pageContextInit , httpResponse }
472
480
return pageContextHttpResponse
473
481
}
0 commit comments