File tree Expand file tree Collapse file tree 5 files changed +38
-5
lines changed
app/middleware/(site)/(core)/~gitbook/icon Expand file tree Collapse file tree 5 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,17 @@ export function createLinker(
72
72
73
73
const siteBasePath = withTrailingSlash ( withLeadingSlash ( servedOn . siteBasePath ) ) ;
74
74
const spaceBasePath = withTrailingSlash ( withLeadingSlash ( servedOn . spaceBasePath ) ) ;
75
+ const protocol = ( ( ) => {
76
+ if ( servedOn . protocol ) {
77
+ return servedOn . protocol ;
78
+ }
79
+
80
+ if ( servedOn . host ) {
81
+ return servedOn . host . startsWith ( 'localhost' ) ? 'http:' : 'https:' ;
82
+ }
83
+
84
+ return 'https:' ;
85
+ } ) ( ) ;
75
86
76
87
const linker : GitBookLinker = {
77
88
toPathInSpace ( relativePath : string ) : string {
@@ -97,7 +108,7 @@ export function createLinker(
97
108
return absolutePath ;
98
109
}
99
110
100
- return `${ servedOn . protocol ?? 'https:' } //${ joinPaths ( servedOn . host , absolutePath ) } ` ;
111
+ return `${ protocol } //${ joinPaths ( servedOn . host , absolutePath ) } ` ;
101
112
} ,
102
113
103
114
toPathForPage ( { pages, page, anchor } ) {
Original file line number Diff line number Diff line change @@ -7,8 +7,21 @@ import { serveIcon } from '@/routes/icon';
7
7
export const runtime = 'edge' ;
8
8
9
9
export async function GET ( req : NextRequest ) {
10
- const pointer = await getSiteContentPointer ( ) ;
11
- const context = await fetchV1ContextForSitePointer ( pointer ) ;
10
+ try {
11
+ console . log ( 'icon: getSiteContentPointer' ) ;
12
+ const pointer = await getSiteContentPointer ( ) ;
13
+ console . log ( 'icon: fetchV1context' ) ;
14
+ const context = await fetchV1ContextForSitePointer ( pointer ) ;
12
15
13
- return serveIcon ( context , req ) ;
16
+ // biome-ignore lint/suspicious/noConsole: we want to log here
17
+ console . log ( `serving icon for ${ context . site . id } ` ) ;
18
+
19
+ return await serveIcon ( context , req ) ;
20
+ } catch ( err ) {
21
+ if ( err instanceof Error ) {
22
+ console . error ( `icon: ${ err . toString ( ) } ` , err . stack ) ;
23
+ }
24
+
25
+ throw err ;
26
+ }
14
27
}
Original file line number Diff line number Diff line change @@ -26,7 +26,12 @@ export const cloudflareDOCache: CacheBackend = {
26
26
return null ;
27
27
}
28
28
29
- return ( await stub . get < CacheEntry > ( key ) ) ?? null ;
29
+ try {
30
+ return ( await stub . get < CacheEntry > ( key ) ) ?? null ;
31
+ } catch ( err ) {
32
+ console . error ( 'cloudflareDO.get' , err ) ;
33
+ return null ;
34
+ }
30
35
}
31
36
) ;
32
37
} ,
Original file line number Diff line number Diff line change @@ -285,6 +285,7 @@ async function getDataFetcherV1(): Promise<GitBookDataFetcher> {
285
285
export async function fetchV1ContextForSitePointer ( pointer : SiteContentPointer ) {
286
286
const baseContext = await getV1BaseContext ( ) ;
287
287
288
+ console . log ( 'icon: baseContext success' ) ;
288
289
const context = await fetchSiteContextByIds ( baseContext , {
289
290
organization : pointer . organizationId ,
290
291
site : pointer . siteId ,
@@ -295,8 +296,10 @@ export async function fetchV1ContextForSitePointer(pointer: SiteContentPointer)
295
296
changeRequest : pointer . changeRequestId ,
296
297
revision : pointer . revisionId ,
297
298
} ) ;
299
+ console . log ( 'icon: context inner success' ) ;
298
300
299
301
context . customization = await getDynamicCustomizationSettings ( context . customization ) ;
302
+ console . log ( 'icon: customization success' ) ;
300
303
301
304
return context ;
302
305
}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ const SIZES = {
27
27
* Generate an icon for a site content.
28
28
*/
29
29
export async function serveIcon ( context : GitBookSiteContext , req : Request ) {
30
+ console . log ( 'icon: serveIcon' , req . url ) ;
30
31
const options = getOptions ( req . url ) ;
31
32
const size = SIZES [ options . size ] ;
32
33
You can’t perform that action at this time.
0 commit comments