@@ -48,16 +48,21 @@ export async function getV1BaseContext(): Promise<GitBookBaseContext> {
4848 const host = await getHost ( ) ;
4949 const basePath = await getBasePath ( ) ;
5050 const siteBasePath = await getSiteBasePath ( ) ;
51+ const protocol = await getProtocol ( ) ;
5152
5253 const linker = createLinker ( {
54+ protocol,
5355 host,
5456 spaceBasePath : basePath ,
5557 siteBasePath : siteBasePath ,
5658 } ) ;
5759
5860 // On V1, we use hard-navigation between different spaces because of layout issues
59- linker . toLinkForContent = ( url ) => {
60- return url ;
61+ linker . toLinkForContent = ( rawURL ) => {
62+ const urlObject = new URL ( rawURL ) ;
63+ return linker . toAbsoluteURL (
64+ linker . toPathInSite ( `${ urlObject . pathname } ${ urlObject . search } ` )
65+ ) ;
6166 } ;
6267
6368 const dataFetcher = getDataFetcherV1 ( ) ;
@@ -66,6 +71,7 @@ export async function getV1BaseContext(): Promise<GitBookBaseContext> {
6671 imagesContextId : host ,
6772 // In V1, we always resize at the top level of the hostname, not relative to the content.
6873 linker : createLinker ( {
74+ protocol,
6975 host,
7076 spaceBasePath : '/' ,
7177 siteBasePath : '/' ,
@@ -401,6 +407,19 @@ export function getSitePointerFromContext(context: GitBookSiteContext): SiteCont
401407 } ;
402408}
403409
410+ /**
411+ * Return the protocol for the current request.
412+ */
413+ async function getProtocol ( ) : Promise < string > {
414+ assertIsNotV2 ( ) ;
415+ const headersList = await headers ( ) ;
416+ const protocol = headersList . get ( 'x-forwarded-proto' ) ?? 'https' ;
417+ if ( protocol . endsWith ( ':' ) ) {
418+ return protocol ;
419+ }
420+ return `${ protocol } :` ;
421+ }
422+
404423/**
405424 * Return the base path for the current request.
406425 * The value will start and finish with /
0 commit comments