Skip to content

Commit 821899a

Browse files
authored
Fix image resizing in v2 when url is being passed as x-gitbook-url (#2921)
1 parent bfcc119 commit 821899a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/gitbook-v2/src/middleware.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ type URLWithMode = { url: URL; mode: 'url' | 'url-host' };
1616

1717
export async function middleware(request: NextRequest) {
1818
try {
19-
/**
20-
* Serve image resizing requests (all requests containing `/~gitbook/image`).
21-
* All URLs containing `/~gitbook/image` are rewritten to `/~gitbook/image`
22-
* and serve from a single route handler.
23-
*
24-
* In GitBook v1: image resizing was done at the root of the hostname (docs.company.com/~gitbook/image)
25-
* In GitBook v2: image resizing is done at the content level (docs.company.com/section/variant/~gitbook/image)
26-
*/
27-
if (request.nextUrl.pathname.endsWith('/~gitbook/image')) {
28-
return serveResizedImage(request);
29-
}
30-
3119
// Route all requests to a site
3220
const extracted = extractURL(request);
3321
if (extracted) {
22+
/**
23+
* Serve image resizing requests (all requests containing `/~gitbook/image`).
24+
* All URLs containing `/~gitbook/image` are rewritten to `/~gitbook/image`
25+
* and serve from a single route handler.
26+
*
27+
* In GitBook v1: image resizing was done at the root of the hostname (docs.company.com/~gitbook/image)
28+
* In GitBook v2: image resizing is done at the content level (docs.company.com/section/variant/~gitbook/image)
29+
*/
30+
if (extracted.url.pathname.endsWith('/~gitbook/image')) {
31+
return serveResizedImage(request);
32+
}
33+
3434
return serveSiteByURL(request, extracted);
3535
}
3636

0 commit comments

Comments
 (0)