mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Fix error for redirects/files on change-requests (#113)
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Demo on how to proxy requests to the renderer with a given space ID and a base path.
|
||||
*/
|
||||
|
||||
const spaceId = Bun.argv[2];
|
||||
const basePath = Bun.argv[3] ?? '';
|
||||
const port = 5000;
|
||||
|
||||
if (!spaceId) {
|
||||
throw new Error('Please provide a space id as an argument');
|
||||
}
|
||||
|
||||
console.log(`Proxying space ${spaceId} on http://localhost:${port}/${basePath}`);
|
||||
|
||||
Bun.serve({
|
||||
port,
|
||||
fetch: async (req) => {
|
||||
const url = new URL(req.url);
|
||||
const upUrl = isNextUrl(url)
|
||||
? `http://localhost:3000${url.pathname}`
|
||||
: `http://localhost:3000/${spaceId}${url.pathname}`;
|
||||
|
||||
const headers = new Headers(req.headers);
|
||||
|
||||
headers.set('x-gitbook-host', url.host);
|
||||
headers.set('x-gitbook-basepath', basePath);
|
||||
|
||||
const response = await fetch(upUrl, {
|
||||
method: req.method,
|
||||
headers: headers,
|
||||
verbose: true,
|
||||
});
|
||||
const body = await response.text();
|
||||
|
||||
return new Response(body, {
|
||||
status: response.status,
|
||||
headers: {
|
||||
'content-type': response.headers.get('content-type') || 'text/html',
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function isNextUrl(url: URL) {
|
||||
return url.pathname.startsWith('/_next/');
|
||||
}
|
||||
+2
-2
@@ -264,7 +264,7 @@ export const getRevisionPageByPath = cache(
|
||||
|
||||
if (pointer.changeRequestId) {
|
||||
return api().spaces.getPageInChangeRequestByPath(
|
||||
spaceId,
|
||||
pointer.spaceId,
|
||||
pointer.changeRequestId,
|
||||
encodedPath,
|
||||
{},
|
||||
@@ -328,7 +328,7 @@ export const getRevisionFile = cache(
|
||||
|
||||
if (pointer.changeRequestId) {
|
||||
return api().spaces.getFileInChangeRequestById(
|
||||
spaceId,
|
||||
pointer.spaceId,
|
||||
pointer.changeRequestId,
|
||||
fileId,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user