From 9d9040f24ea7dbd92233d9ac2e5ea06aecd91633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 23 Jan 2024 21:38:28 +0100 Subject: [PATCH] Fix error for redirects/files on change-requests (#113) --- dev/test-proxy-server.ts | 46 ---------------------------------------- src/lib/api.ts | 4 ++-- 2 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 dev/test-proxy-server.ts diff --git a/dev/test-proxy-server.ts b/dev/test-proxy-server.ts deleted file mode 100644 index 43bc9cd8b..000000000 --- a/dev/test-proxy-server.ts +++ /dev/null @@ -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/'); -} diff --git a/src/lib/api.ts b/src/lib/api.ts index e6818bb76..f72556075 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -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, {