Skip to content

Commit 05affac

Browse files
authored
Add support for proxy sites using x-gitbook-url in v2 (#2901)
1 parent 453a459 commit 05affac

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/gitbook-v2/src/middleware.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,20 @@ function serveErrorResponse(error: Error) {
107107
}
108108

109109
/**
110-
* The URL of the GitBook content can be passed in 2 different ways:
110+
* The URL of the GitBook content can be passed in 3 different ways:
111+
* - The request URL is in the `X-GitBook-URL` header.
111112
* - Hostname is in the `X-GitBook-Host` header and the pathname is the path in the request URL.
112113
* - The request URL is matching `/url/:url`
113114
*/
114115
function extractURL(request: NextRequest): URLWithMode | null {
116+
const xGitbookUrl = request.headers.get('x-gitbook-url');
117+
if (xGitbookUrl) {
118+
return {
119+
url: new URL(xGitbookUrl),
120+
mode: 'url-host',
121+
};
122+
}
123+
115124
const xGitbookHost = request.headers.get('x-gitbook-host');
116125
if (xGitbookHost) {
117126
return {

0 commit comments

Comments
 (0)