From 58cef9b47f1de2da56b265865f0797a194798ddb Mon Sep 17 00:00:00 2001 From: taranvohra Date: Fri, 4 Apr 2025 12:43:51 +0200 Subject: [PATCH 01/18] Use the proxy request identifier for storing the va cookie in the case of proxy sites --- packages/gitbook-v2/src/lib/data/index.ts | 1 + packages/gitbook-v2/src/lib/data/proxy.ts | 15 +++++++++++++++ .../src/lib/images/getImageResizingContextId.ts | 9 ++++----- packages/gitbook-v2/src/middleware.ts | 15 ++++++++++++++- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 packages/gitbook-v2/src/lib/data/proxy.ts diff --git a/packages/gitbook-v2/src/lib/data/index.ts b/packages/gitbook-v2/src/lib/data/index.ts index 12e06f8cfc..b50f7e127b 100644 --- a/packages/gitbook-v2/src/lib/data/index.ts +++ b/packages/gitbook-v2/src/lib/data/index.ts @@ -4,3 +4,4 @@ export * from './pages'; export * from './urls'; export * from './errors'; export * from './lookup'; +export * from './proxy'; diff --git a/packages/gitbook-v2/src/lib/data/proxy.ts b/packages/gitbook-v2/src/lib/data/proxy.ts new file mode 100644 index 0000000000..665466503d --- /dev/null +++ b/packages/gitbook-v2/src/lib/data/proxy.ts @@ -0,0 +1,15 @@ +/** + * Check if the request to the site was through a proxy. + */ +export function isProxyRequest(requestURL: URL): boolean { + return ( + requestURL.host === 'proxy.gitbook.site' || requestURL.host === 'proxy.gitbook-staging.site' + ); +} + +export function getProxyRequestIdentifier(requestURL: URL): string { + // For proxy requests, we extract the site ID from the pathname + // e.g. https://proxy.gitbook.site/site/siteId/... + const pathname = requestURL.pathname.slice(1).split('/'); + return pathname.slice(0, 2).join('/'); +} diff --git a/packages/gitbook-v2/src/lib/images/getImageResizingContextId.ts b/packages/gitbook-v2/src/lib/images/getImageResizingContextId.ts index 58b5608bbb..82f9225262 100644 --- a/packages/gitbook-v2/src/lib/images/getImageResizingContextId.ts +++ b/packages/gitbook-v2/src/lib/images/getImageResizingContextId.ts @@ -1,13 +1,12 @@ +import { getProxyRequestIdentifier, isProxyRequest } from '../data'; + /** * Get the site identifier to use for image resizing for an incoming request. * This identifier can be obtained before resolving the request URL. */ export function getImageResizingContextId(url: URL): string { - if (url.host === 'proxy.gitbook.site' || url.host === 'proxy.gitbook-staging.site') { - // For proxy requests, we extract the site ID from the pathname - // e.g. https://proxy.gitbook.site/site/siteId/... - const pathname = url.pathname.slice(1).split('/'); - return pathname.slice(0, 2).join('/'); + if (isProxyRequest(url)) { + return getProxyRequestIdentifier(url); } return url.host; diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index ae5aa4a368..80f4853957 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -16,7 +16,9 @@ import { import { serveResizedImage } from '@/routes/image'; import { DataFetcherError, + getProxyRequestIdentifier, getPublishedContentByURL, + isProxyRequest, normalizeURL, throwIfDataError, } from '@v2/lib/data'; @@ -137,7 +139,18 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) { return NextResponse.redirect(siteURLData.redirect); } - cookies.push(...getResponseCookiesForVisitorAuth(siteURLData.siteBasePath, visitorToken)); + cookies.push( + ...getResponseCookiesForVisitorAuth( + // The siteRequestURL for proxy requests is of the form `https://proxy.gitbook.com/site/siteId/...` + // In such cases, we should not use the resolved siteBasePath for the cookie because for subsequent requests + // we will not have the siteBasePath in the request URL in order to retrieve the cookie. So we use the + // proxy identifier instead. + isProxyRequest(siteRequestURL) + ? getProxyRequestIdentifier(siteRequestURL) + : siteURLData.siteBasePath, + visitorToken + ) + ); // We use the host/origin from the canonical URL to ensure the links are // correctly generated when the site is proxied. e.g. https://proxy.gitbook.com/site/siteId/... From db7698f9e74dd4ece3645a622af43468640513bf Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 16:44:59 +0530 Subject: [PATCH 02/18] add e2e tests --- bun.lock | 72 ++++++++++++++++++++++----- packages/gitbook/e2e/internal.spec.ts | 37 ++++++++++++++ 2 files changed, 97 insertions(+), 12 deletions(-) diff --git a/bun.lock b/bun.lock index ebdd6b0a6f..8aeca46c2e 100644 --- a/bun.lock +++ b/bun.lock @@ -165,7 +165,7 @@ "name": "@gitbook/icons", "version": "0.2.0", "bin": { - "gitbook-icons": "./bin/gitbook-icons.js" + "gitbook-icons": "./bin/gitbook-icons.js", }, "dependencies": { "@fortawesome/fontawesome-free": "^6.6.0", @@ -222,7 +222,7 @@ "name": "@gitbook/react-math", "version": "0.6.0", "bin": { - "gitbook-math": "./bin/gitbook-math.js" + "gitbook-math": "./bin/gitbook-math.js", }, "dependencies": { "object-hash": "^3.0.0", @@ -676,6 +676,8 @@ "@img/sharp-libvips-linux-arm64": ["@img/sharp-libvips-linux-arm64@1.0.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA=="], + "@img/sharp-libvips-linux-ppc64": ["@img/sharp-libvips-linux-ppc64@1.1.0", "", { "os": "linux", "cpu": "ppc64" }, "sha512-tiXxFZFbhnkWE2LA8oQj7KYR+bWBkiV2nilRldT7bqoEZ4HiDOcePr9wVDAZPi/Id5fT1oY9iGnDq20cwUz8lQ=="], + "@img/sharp-libvips-linux-s390x": ["@img/sharp-libvips-linux-s390x@1.0.4", "", { "os": "linux", "cpu": "s390x" }, "sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA=="], "@img/sharp-libvips-linux-x64": ["@img/sharp-libvips-linux-x64@1.0.4", "", { "os": "linux", "cpu": "x64" }, "sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw=="], @@ -4022,7 +4024,7 @@ "gaxios/node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="], - "gitbook-v2/next": ["next@15.3.0-canary.42", "", { "dependencies": { "@next/env": "15.3.0-canary.42", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.3.0-canary.42", "@next/swc-darwin-x64": "15.3.0-canary.42", "@next/swc-linux-arm64-gnu": "15.3.0-canary.42", "@next/swc-linux-arm64-musl": "15.3.0-canary.42", "@next/swc-linux-x64-gnu": "15.3.0-canary.42", "@next/swc-linux-x64-musl": "15.3.0-canary.42", "@next/swc-win32-arm64-msvc": "15.3.0-canary.42", "@next/swc-win32-x64-msvc": "15.3.0-canary.42", "sharp": "^0.33.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-f1KQC+GOE72/MYvxEedYY+jpZch3pzNrz51euqt87xWGiRlIngO2VQEbFDwQHZwvzkOtKmC1lDd2Clkd5sLsTQ=="], + "gitbook-v2/next": ["next@15.3.0-canary.43", "", { "dependencies": { "@next/env": "15.3.0-canary.43", "@swc/counter": "0.1.3", "@swc/helpers": "0.5.15", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", "styled-jsx": "5.1.6" }, "optionalDependencies": { "@next/swc-darwin-arm64": "15.3.0-canary.43", "@next/swc-darwin-x64": "15.3.0-canary.43", "@next/swc-linux-arm64-gnu": "15.3.0-canary.43", "@next/swc-linux-arm64-musl": "15.3.0-canary.43", "@next/swc-linux-x64-gnu": "15.3.0-canary.43", "@next/swc-linux-x64-musl": "15.3.0-canary.43", "@next/swc-win32-arm64-msvc": "15.3.0-canary.43", "@next/swc-win32-x64-msvc": "15.3.0-canary.43", "sharp": "^0.34.1" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", "@playwright/test": "^1.41.2", "babel-plugin-react-compiler": "*", "react": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "react-dom": "^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ^19.0.0", "sass": "^1.3.0" }, "optionalPeers": ["@opentelemetry/api", "@playwright/test", "babel-plugin-react-compiler", "sass"], "bin": { "next": "dist/bin/next" } }, "sha512-am6xpZIx2P0VJ26N7K2CImmznYUP65XS0e0nkYtypWf/RiMsScwmCqrA4qrEK9u/tiPlA+583IcQPos9yKLg1Q=="], "global-dirs/ini": ["ini@1.3.7", "", {}, "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ=="], @@ -4890,26 +4892,28 @@ "gaxios/https-proxy-agent/debug": ["debug@4.3.7", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ=="], - "gitbook-v2/next/@next/env": ["@next/env@15.3.0-canary.42", "", {}, "sha512-J/lYYosUhRJwLejxEkdXoc8NOhJKzMA/aUTQaXD1qGzMWDkvQ5FisO336WMKHRMIVXf1yu2G4JMKOZJ50Qhq+w=="], + "gitbook-v2/next/@next/env": ["@next/env@15.3.0-canary.43", "", {}, "sha512-ogryUGufxhtidxr/42NY6+ADlvxt9Hq6Q/DOMS/20vGuePZ70wO6Z5m1RP3Q397RGgpe1gSWyYdlg+Mt7H4KeQ=="], - "gitbook-v2/next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.3.0-canary.42", "", { "os": "darwin", "cpu": "arm64" }, "sha512-9RlirdgHKaoI97IfVqXlRxhZNuqK9IuWdEu5xZ7fLphYKF+HKAMuqIO1/z53Bl4CSRM7DDpRiyXAyqDJ4VBr7g=="], + "gitbook-v2/next/@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.3.0-canary.43", "", { "os": "darwin", "cpu": "arm64" }, "sha512-eXrs8CyIBgdnMTNjku+h/xm61gmRCcKAT+tM2CjpEXbEqXBux5hRIakOk5kJJDu2fA2P3pzQGt5PRD1hg4srXA=="], - "gitbook-v2/next/@next/swc-darwin-x64": ["@next/swc-darwin-x64@15.3.0-canary.42", "", { "os": "darwin", "cpu": "x64" }, "sha512-ZAUP4zGtED0mzFYZprch/Pqz3UCnOAee/IdHsKl7uVlmnUyX43I6dDDmk1Srae5RlLu1pVdUkT2tJfT1JKo06w=="], + "gitbook-v2/next/@next/swc-darwin-x64": ["@next/swc-darwin-x64@15.3.0-canary.43", "", { "os": "darwin", "cpu": "x64" }, "sha512-iRGvblEh/b2grxkkp9pT+yea9EzGNM4tLyUZoCzkejkU2jMLsn2DH6h3bQwCfEYZL3YFGsYmVISrVCOVi8LeMw=="], - "gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@15.3.0-canary.42", "", { "os": "linux", "cpu": "arm64" }, "sha512-ttgFELQ0oebZNDQweq0jh7ixk8kfUeC6xr3qzjF0eqQygy+DuhEjAzDYZsfCi6G1ToRXJ8+spkZS7Lhv6GNMqw=="], + "gitbook-v2/next/@next/swc-linux-arm64-gnu": ["@next/swc-linux-arm64-gnu@15.3.0-canary.43", "", { "os": "linux", "cpu": "arm64" }, "sha512-IqknHGNxpL03uIutIuv7FPjGHuD/AnJVC5exi5g+C7P3f6JVvOjFLS264eqi91tVCXhN2LpcKNGwTlK81bJVVg=="], - "gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@15.3.0-canary.42", "", { "os": "linux", "cpu": "arm64" }, "sha512-XVhtQ6RMbnQMxrm0nWJ5lOrr/48U+Gv8A5mOFwh1URiq9Ur1QBHIzdYJRUFyoN3n0+qSplOyqCzhff3YRauNRQ=="], + "gitbook-v2/next/@next/swc-linux-arm64-musl": ["@next/swc-linux-arm64-musl@15.3.0-canary.43", "", { "os": "linux", "cpu": "arm64" }, "sha512-FbO0dnFsNe3f1LWTn4vyXTWTSrZdwNRnURYExSQ+0AINHphNfwKQNrPqVLrapQ9CAOCOz8R5p9Kf1++IsH3JJQ=="], - "gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@15.3.0-canary.42", "", { "os": "linux", "cpu": "x64" }, "sha512-ycfjoWE9vxUsZc6LW27aiqiq0m7OtjVz4Ptd9gW5ya8YJvhSWK/0kXo9CVadIFMlX4xJpKl194bZZCJrbD3pvA=="], + "gitbook-v2/next/@next/swc-linux-x64-gnu": ["@next/swc-linux-x64-gnu@15.3.0-canary.43", "", { "os": "linux", "cpu": "x64" }, "sha512-MAaLEm8eO6Xir3YC3xLYDHDjLGogAAGRrxhuflvaqAtGQZ6NIMG4YjvAyramYTq/SwrUIDobggKxdQLtu8/pPQ=="], - "gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@15.3.0-canary.42", "", { "os": "linux", "cpu": "x64" }, "sha512-jr5CIZ6C1QJg2AJQY/vCELLR0EH1DyL+cRfPTDHC5lt2vI3AFsUO6n3rmN0rtOZuMQG4zH3ZrRgMHcZaX5aaDQ=="], + "gitbook-v2/next/@next/swc-linux-x64-musl": ["@next/swc-linux-x64-musl@15.3.0-canary.43", "", { "os": "linux", "cpu": "x64" }, "sha512-gdwF79/EQjY3zgcolO0jlDe0yfII9tXyXQeqL+uvzA8gZT5FpH0KkwSWzxj8EUswWzZcprbDa87sq8H0Eo+whw=="], - "gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@15.3.0-canary.42", "", { "os": "win32", "cpu": "arm64" }, "sha512-0Qfe9yKHExdVDQd5NKpGvWYGB0Uz45r4OvxjpOyy5QMZ5j/wzg1BhgM2EfoXoEiBrzeEXnZ2MTk14GwS+BzQLQ=="], + "gitbook-v2/next/@next/swc-win32-arm64-msvc": ["@next/swc-win32-arm64-msvc@15.3.0-canary.43", "", { "os": "win32", "cpu": "arm64" }, "sha512-5WYne3jvo1478kUfe901wFxvPMdC8tRKundKIgU5Upe1HafMMS7ymm1hQ7CUpp3/1vY/R1TV1oKHHJfqDubiNg=="], - "gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@15.3.0-canary.42", "", { "os": "win32", "cpu": "x64" }, "sha512-SJ5Qj+2duEuwILQLAXH12J74XqJMiulC/VC5+f64FurqC34ESVsgtgzZQAfhkDmp8B/8D24wgL0LTivsVO1vbw=="], + "gitbook-v2/next/@next/swc-win32-x64-msvc": ["@next/swc-win32-x64-msvc@15.3.0-canary.43", "", { "os": "win32", "cpu": "x64" }, "sha512-xE3WZhwjb91eezecVsmXn/OtdISfMsIfS3t0ZXsS/+bMvO/LZLdcVBtl0Zy5yR+XJyKfXXmwpdYbL6WH4dGuQg=="], "gitbook-v2/next/postcss": ["postcss@8.4.31", "", { "dependencies": { "nanoid": "^3.3.6", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } }, "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ=="], + "gitbook-v2/next/sharp": ["sharp@0.34.1", "", { "dependencies": { "color": "^4.2.3", "detect-libc": "^2.0.3", "semver": "^7.7.1" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.34.1", "@img/sharp-darwin-x64": "0.34.1", "@img/sharp-libvips-darwin-arm64": "1.1.0", "@img/sharp-libvips-darwin-x64": "1.1.0", "@img/sharp-libvips-linux-arm": "1.1.0", "@img/sharp-libvips-linux-arm64": "1.1.0", "@img/sharp-libvips-linux-ppc64": "1.1.0", "@img/sharp-libvips-linux-s390x": "1.1.0", "@img/sharp-libvips-linux-x64": "1.1.0", "@img/sharp-libvips-linuxmusl-arm64": "1.1.0", "@img/sharp-libvips-linuxmusl-x64": "1.1.0", "@img/sharp-linux-arm": "0.34.1", "@img/sharp-linux-arm64": "0.34.1", "@img/sharp-linux-s390x": "0.34.1", "@img/sharp-linux-x64": "0.34.1", "@img/sharp-linuxmusl-arm64": "0.34.1", "@img/sharp-linuxmusl-x64": "0.34.1", "@img/sharp-wasm32": "0.34.1", "@img/sharp-win32-ia32": "0.34.1", "@img/sharp-win32-x64": "0.34.1" } }, "sha512-1j0w61+eVxu7DawFJtnfYcvSv6qPFvfTaqzTQ2BLknVhHTwGS8sc63ZBF4rzkWMBVKybo4S5OBtDdZahh2A1xg=="], + "gitbook-v2/next/styled-jsx": ["styled-jsx@5.1.6", "", { "dependencies": { "client-only": "0.0.1" }, "peerDependencies": { "react": ">= 16.8.0 || 17.x.x || ^18.0.0-0 || ^19.0.0-0" } }, "sha512-qSVyDTeMotdvQYoHWLNGwRFJHC+i+ZvdBRYosOFgC+Wg1vx4frN2/RG/NA7SYqqvKNLf39P2LSRA2pu6n0XYZA=="], "globby/fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], @@ -5126,6 +5130,46 @@ "gitbook-v2/next/postcss/nanoid": ["nanoid@3.3.7", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g=="], + "gitbook-v2/next/sharp/@img/sharp-darwin-arm64": ["@img/sharp-darwin-arm64@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-darwin-arm64": "1.1.0" }, "os": "darwin", "cpu": "arm64" }, "sha512-pn44xgBtgpEbZsu+lWf2KNb6OAf70X68k+yk69Ic2Xz11zHR/w24/U49XT7AeRwJ0Px+mhALhU5LPci1Aymk7A=="], + + "gitbook-v2/next/sharp/@img/sharp-darwin-x64": ["@img/sharp-darwin-x64@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-darwin-x64": "1.1.0" }, "os": "darwin", "cpu": "x64" }, "sha512-VfuYgG2r8BpYiOUN+BfYeFo69nP/MIwAtSJ7/Zpxc5QF3KS22z8Pvg3FkrSFJBPNQ7mmcUcYQFBmEQp7eu1F8Q=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-darwin-arm64": ["@img/sharp-libvips-darwin-arm64@1.1.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-HZ/JUmPwrJSoM4DIQPv/BfNh9yrOA8tlBbqbLz4JZ5uew2+o22Ik+tHQJcih7QJuSa0zo5coHTfD5J8inqj9DA=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-darwin-x64": ["@img/sharp-libvips-darwin-x64@1.1.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-Xzc2ToEmHN+hfvsl9wja0RlnXEgpKNmftriQp6XzY/RaSfwD9th+MSh0WQKzUreLKKINb3afirxW7A0fz2YWuQ=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-linux-arm": ["@img/sharp-libvips-linux-arm@1.1.0", "", { "os": "linux", "cpu": "arm" }, "sha512-s8BAd0lwUIvYCJyRdFqvsj+BJIpDBSxs6ivrOPm/R7piTs5UIwY5OjXrP2bqXC9/moGsyRa37eYWYCOGVXxVrA=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-linux-arm64": ["@img/sharp-libvips-linux-arm64@1.1.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-IVfGJa7gjChDET1dK9SekxFFdflarnUB8PwW8aGwEoF3oAsSDuNUTYS+SKDOyOJxQyDC1aPFMuRYLoDInyV9Ew=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-linux-s390x": ["@img/sharp-libvips-linux-s390x@1.1.0", "", { "os": "linux", "cpu": "s390x" }, "sha512-xukSwvhguw7COyzvmjydRb3x/09+21HykyapcZchiCUkTThEQEOMtBj9UhkaBRLuBrgLFzQ2wbxdeCCJW/jgJA=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-linux-x64": ["@img/sharp-libvips-linux-x64@1.1.0", "", { "os": "linux", "cpu": "x64" }, "sha512-yRj2+reB8iMg9W5sULM3S74jVS7zqSzHG3Ol/twnAAkAhnGQnpjj6e4ayUz7V+FpKypwgs82xbRdYtchTTUB+Q=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-linuxmusl-arm64": ["@img/sharp-libvips-linuxmusl-arm64@1.1.0", "", { "os": "linux", "cpu": "arm64" }, "sha512-jYZdG+whg0MDK+q2COKbYidaqW/WTz0cc1E+tMAusiDygrM4ypmSCjOJPmFTvHHJ8j/6cAGyeDWZOsK06tP33w=="], + + "gitbook-v2/next/sharp/@img/sharp-libvips-linuxmusl-x64": ["@img/sharp-libvips-linuxmusl-x64@1.1.0", "", { "os": "linux", "cpu": "x64" }, "sha512-wK7SBdwrAiycjXdkPnGCPLjYb9lD4l6Ze2gSdAGVZrEL05AOUJESWU2lhlC+Ffn5/G+VKuSm6zzbQSzFX/P65A=="], + + "gitbook-v2/next/sharp/@img/sharp-linux-arm": ["@img/sharp-linux-arm@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-linux-arm": "1.1.0" }, "os": "linux", "cpu": "arm" }, "sha512-anKiszvACti2sGy9CirTlNyk7BjjZPiML1jt2ZkTdcvpLU1YH6CXwRAZCA2UmRXnhiIftXQ7+Oh62Ji25W72jA=="], + + "gitbook-v2/next/sharp/@img/sharp-linux-arm64": ["@img/sharp-linux-arm64@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-linux-arm64": "1.1.0" }, "os": "linux", "cpu": "arm64" }, "sha512-kX2c+vbvaXC6vly1RDf/IWNXxrlxLNpBVWkdpRq5Ka7OOKj6nr66etKy2IENf6FtOgklkg9ZdGpEu9kwdlcwOQ=="], + + "gitbook-v2/next/sharp/@img/sharp-linux-s390x": ["@img/sharp-linux-s390x@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-linux-s390x": "1.1.0" }, "os": "linux", "cpu": "s390x" }, "sha512-7s0KX2tI9mZI2buRipKIw2X1ufdTeaRgwmRabt5bi9chYfhur+/C1OXg3TKg/eag1W+6CCWLVmSauV1owmRPxA=="], + + "gitbook-v2/next/sharp/@img/sharp-linux-x64": ["@img/sharp-linux-x64@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-linux-x64": "1.1.0" }, "os": "linux", "cpu": "x64" }, "sha512-wExv7SH9nmoBW3Wr2gvQopX1k8q2g5V5Iag8Zk6AVENsjwd+3adjwxtp3Dcu2QhOXr8W9NusBU6XcQUohBZ5MA=="], + + "gitbook-v2/next/sharp/@img/sharp-linuxmusl-arm64": ["@img/sharp-linuxmusl-arm64@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-linuxmusl-arm64": "1.1.0" }, "os": "linux", "cpu": "arm64" }, "sha512-DfvyxzHxw4WGdPiTF0SOHnm11Xv4aQexvqhRDAoD00MzHekAj9a/jADXeXYCDFH/DzYruwHbXU7uz+H+nWmSOQ=="], + + "gitbook-v2/next/sharp/@img/sharp-linuxmusl-x64": ["@img/sharp-linuxmusl-x64@0.34.1", "", { "optionalDependencies": { "@img/sharp-libvips-linuxmusl-x64": "1.1.0" }, "os": "linux", "cpu": "x64" }, "sha512-pax/kTR407vNb9qaSIiWVnQplPcGU8LRIJpDT5o8PdAx5aAA7AS3X9PS8Isw1/WfqgQorPotjrZL3Pqh6C5EBg=="], + + "gitbook-v2/next/sharp/@img/sharp-wasm32": ["@img/sharp-wasm32@0.34.1", "", { "dependencies": { "@emnapi/runtime": "^1.4.0" }, "cpu": "none" }, "sha512-YDybQnYrLQfEpzGOQe7OKcyLUCML4YOXl428gOOzBgN6Gw0rv8dpsJ7PqTHxBnXnwXr8S1mYFSLSa727tpz0xg=="], + + "gitbook-v2/next/sharp/@img/sharp-win32-ia32": ["@img/sharp-win32-ia32@0.34.1", "", { "os": "win32", "cpu": "ia32" }, "sha512-WKf/NAZITnonBf3U1LfdjoMgNO5JYRSlhovhRhMxXVdvWYveM4kM3L8m35onYIdh75cOMCo1BexgVQcCDzyoWw=="], + + "gitbook-v2/next/sharp/@img/sharp-win32-x64": ["@img/sharp-win32-x64@0.34.1", "", { "os": "win32", "cpu": "x64" }, "sha512-hw1iIAHpNE8q3uMIRCgGOeDoz9KtFNarFLQclLxr/LK1VBkj8nby18RjFvr6aP7USRYAjTZW6yisnBWMX571Tw=="], + + "gitbook-v2/next/sharp/semver": ["semver@7.7.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA=="], + "rimraf/glob/path-scurry/lru-cache": ["lru-cache@10.4.3", "", {}, "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ=="], "sucrase/glob/path-scurry/lru-cache": ["lru-cache@10.4.3", "", {}, "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ=="], @@ -5168,6 +5212,8 @@ "@vercel/nft/glob/minimatch/brace-expansion/balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="], + "gitbook-v2/next/sharp/@img/sharp-wasm32/@emnapi/runtime": ["@emnapi/runtime@1.4.0", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-64WYIf4UYcdLnbKn/umDlNjQDSS8AgZrI/R9+x5ilkUVFxXcA1Ebl+gQLc/6mERA4407Xof0R7wEyEuj091CVw=="], + "@aws-sdk/core/@smithy/smithy-client/@smithy/util-stream/@smithy/fetch-http-handler/@smithy/querystring-builder/@smithy/util-uri-escape": ["@smithy/util-uri-escape@4.0.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-77yfbCbQMtgtTylO9itEAdpPXSog3ZxMe09AEhm0dU0NLTalV70ghDZFR+Nfi1C60jnJoh/Re4090/DuZh2Omg=="], "@aws-sdk/core/@smithy/smithy-client/@smithy/util-stream/@smithy/node-http-handler/@smithy/querystring-builder/@smithy/util-uri-escape": ["@smithy/util-uri-escape@4.0.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-77yfbCbQMtgtTylO9itEAdpPXSog3ZxMe09AEhm0dU0NLTalV70ghDZFR+Nfi1C60jnJoh/Re4090/DuZh2Omg=="], @@ -5175,5 +5221,7 @@ "@aws-sdk/middleware-sdk-sqs/@smithy/smithy-client/@smithy/util-stream/@smithy/fetch-http-handler/@smithy/querystring-builder/@smithy/util-uri-escape": ["@smithy/util-uri-escape@4.0.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-77yfbCbQMtgtTylO9itEAdpPXSog3ZxMe09AEhm0dU0NLTalV70ghDZFR+Nfi1C60jnJoh/Re4090/DuZh2Omg=="], "@aws-sdk/middleware-sdk-sqs/@smithy/smithy-client/@smithy/util-stream/@smithy/node-http-handler/@smithy/querystring-builder/@smithy/util-uri-escape": ["@smithy/util-uri-escape@4.0.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-77yfbCbQMtgtTylO9itEAdpPXSog3ZxMe09AEhm0dU0NLTalV70ghDZFR+Nfi1C60jnJoh/Re4090/DuZh2Omg=="], + + "gitbook-v2/next/sharp/@img/sharp-wasm32/@emnapi/runtime/tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], } } diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index 4b244a0c4a..1a15c36021 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -419,6 +419,43 @@ const testCases: TestsCase[] = [ }, ], }, + { + name: 'Site subdirectory (proxy)', + skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel', + contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', + tests: [ + { + name: 'Main', + url: '', + fullPage: true, + }, + ], + }, + { + name: 'Site subdirectory (proxy) with VA', + skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel', + contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', + tests: [ + { + name: 'Main', + url: () => { + const privateKey = + 'rqSfA6x7eAKx1qDRCDq9aCXwivpUvQ8YkXeDdFvCCUa9QchIcM7pF1iJ4o7AGOU49spmOWjKoIPtX0pVUVQ81w=='; + const token = jwt.sign( + { + name: 'gitbook-open-tests', + }, + privateKey, + { + expiresIn: '24h', + } + ); + return `?jwt_token=${token}`; + }, + fullPage: true, + }, + ], + }, { name: 'Content tests', contentBaseURL: 'https://gitbook.gitbook.io/test-gitbook-open/', From d5f5bb38d963b604c97866a6615db1a8b29d5295 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:01:58 +0530 Subject: [PATCH 03/18] use xforwardedhost in env --- .github/workflows/deploy-preview.yaml | 27 ++++++++++++++++++++++++--- packages/gitbook-v2/src/middleware.ts | 2 +- packages/gitbook/e2e/internal.spec.ts | 8 ++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-preview.yaml b/.github/workflows/deploy-preview.yaml index 4926cf07f9..2497e71c6b 100644 --- a/.github/workflows/deploy-preview.yaml +++ b/.github/workflows/deploy-preview.yaml @@ -10,7 +10,7 @@ jobs: deploy-v1-cloudflare: name: Deploy v1 to Cloudflare Pages runs-on: ubuntu-latest - environment: + environment: name: ${{ github.ref == 'refs/heads/main' && '1c-production' || '1c-preview' }} url: ${{ steps.deploy.outputs.deployment-url }} permissions: @@ -57,7 +57,7 @@ jobs: deploy-v2-vercel: name: Deploy v2 to Vercel (preview) runs-on: ubuntu-latest - environment: + environment: name: 2v-preview url: ${{ steps.deploy.outputs.deployment-url }} outputs: @@ -78,7 +78,7 @@ jobs: deploy-v2-cloudflare: name: Deploy v2 to Cloudflare Worker (preview) runs-on: ubuntu-latest - environment: + environment: name: 2c-preview url: ${{ steps.deploy.outputs.deployment-url }} outputs: @@ -187,6 +187,27 @@ jobs: SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/ ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} ARGOS_BUILD_NAME: 'v2-vercel' + visual-testing-v2-vercel-proxy: + runs-on: ubuntu-latest + name: Visual Testing v2 (Proxy) + needs: deploy-v2-vercel + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Bun + uses: ./.github/composite/setup-bun + - name: Install dependencies + run: bun install --frozen-lockfile + - name: Setup Playwright + uses: ./.github/actions/setup-playwright + - name: Run Playwright tests + run: bun e2e + env: + BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }} + ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} + ARGOS_BUILD_NAME: 'v2-vercel' + X_FORWARDED_HOST: 'proxy.gitbook.site' visual-testing-customers-v1: runs-on: ubuntu-latest name: Visual Testing Customers v1 diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index fc99e21931..bc2950c38d 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -401,7 +401,7 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { return null; } - const xForwardedHost = request.headers.get('x-forwarded-host'); + const xForwardedHost = process.env.X_FORWARDED_HOST ?? request.headers.get('x-forwarded-host'); // The x-forwarded-host is set by Vercel for all requests // so we ignore it if the hostname is the same as the instance one. if (xForwardedHost) { diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index 1a15c36021..3db5008b47 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -421,7 +421,9 @@ const testCases: TestsCase[] = [ }, { name: 'Site subdirectory (proxy)', - skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel', + skip: + process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && + typeof process.env.X_FORWARED_HOST === 'undefined', contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', tests: [ { @@ -433,7 +435,9 @@ const testCases: TestsCase[] = [ }, { name: 'Site subdirectory (proxy) with VA', - skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel', + skip: + process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && + typeof process.env.X_FORWARED_HOST === 'undefined', contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', tests: [ { From d707e6c85725e0e119bc41ab7379f9d3fb2ab58b Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:14:15 +0530 Subject: [PATCH 04/18] fix typo --- packages/gitbook/e2e/internal.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index 3db5008b47..e777d39cb3 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -423,7 +423,7 @@ const testCases: TestsCase[] = [ name: 'Site subdirectory (proxy)', skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && - typeof process.env.X_FORWARED_HOST === 'undefined', + typeof process.env.X_FORWARDED_HOST === 'undefined', contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', tests: [ { @@ -437,7 +437,7 @@ const testCases: TestsCase[] = [ name: 'Site subdirectory (proxy) with VA', skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && - typeof process.env.X_FORWARED_HOST === 'undefined', + typeof process.env.X_FORWARDED_HOST === 'undefined', contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', tests: [ { From fb3cadd5a887799c3159ed8d4082d45caf4128e2 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:36:35 +0530 Subject: [PATCH 05/18] proxy tests --- .github/workflows/deploy-preview.yaml | 4 +-- packages/gitbook/e2e/internal.spec.ts | 41 --------------------- packages/gitbook/e2e/proxy.spec.ts | 52 +++++++++++++++++++++++++++ packages/gitbook/package.json | 1 + 4 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 packages/gitbook/e2e/proxy.spec.ts diff --git a/.github/workflows/deploy-preview.yaml b/.github/workflows/deploy-preview.yaml index 2497e71c6b..4504f2a74d 100644 --- a/.github/workflows/deploy-preview.yaml +++ b/.github/workflows/deploy-preview.yaml @@ -187,7 +187,7 @@ jobs: SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/ ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} ARGOS_BUILD_NAME: 'v2-vercel' - visual-testing-v2-vercel-proxy: + visual-testing-proxy-v2-vercel: runs-on: ubuntu-latest name: Visual Testing v2 (Proxy) needs: deploy-v2-vercel @@ -202,7 +202,7 @@ jobs: - name: Setup Playwright uses: ./.github/actions/setup-playwright - name: Run Playwright tests - run: bun e2e + run: bun e2e-proxy env: BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }} ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index e777d39cb3..4b244a0c4a 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -419,47 +419,6 @@ const testCases: TestsCase[] = [ }, ], }, - { - name: 'Site subdirectory (proxy)', - skip: - process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && - typeof process.env.X_FORWARDED_HOST === 'undefined', - contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', - tests: [ - { - name: 'Main', - url: '', - fullPage: true, - }, - ], - }, - { - name: 'Site subdirectory (proxy) with VA', - skip: - process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && - typeof process.env.X_FORWARDED_HOST === 'undefined', - contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', - tests: [ - { - name: 'Main', - url: () => { - const privateKey = - 'rqSfA6x7eAKx1qDRCDq9aCXwivpUvQ8YkXeDdFvCCUa9QchIcM7pF1iJ4o7AGOU49spmOWjKoIPtX0pVUVQ81w=='; - const token = jwt.sign( - { - name: 'gitbook-open-tests', - }, - privateKey, - { - expiresIn: '24h', - } - ); - return `?jwt_token=${token}`; - }, - fullPage: true, - }, - ], - }, { name: 'Content tests', contentBaseURL: 'https://gitbook.gitbook.io/test-gitbook-open/', diff --git a/packages/gitbook/e2e/proxy.spec.ts b/packages/gitbook/e2e/proxy.spec.ts new file mode 100644 index 0000000000..7ee2d677bb --- /dev/null +++ b/packages/gitbook/e2e/proxy.spec.ts @@ -0,0 +1,52 @@ +import jwt from 'jsonwebtoken'; +import { type TestsCase, runTestCases } from './util'; + +/** + * This test suite is designed to run tests for the site subdirectory + * feature using a proxy. + */ +const testCases: TestsCase[] = [ + { + name: 'Site subdirectory (proxy)', + skip: + process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && + typeof process.env.X_FORWARDED_HOST === 'undefined', + contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', + tests: [ + { + name: 'Main', + url: '', + fullPage: true, + }, + ], + }, + { + name: 'Site subdirectory (proxy) with VA', + skip: + process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && + typeof process.env.X_FORWARDED_HOST === 'undefined', + contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', + tests: [ + { + name: 'Main', + url: () => { + const privateKey = + 'rqSfA6x7eAKx1qDRCDq9aCXwivpUvQ8YkXeDdFvCCUa9QchIcM7pF1iJ4o7AGOU49spmOWjKoIPtX0pVUVQ81w=='; + const token = jwt.sign( + { + name: 'gitbook-open-tests', + }, + privateKey, + { + expiresIn: '24h', + } + ); + return `?jwt_token=${token}`; + }, + fullPage: true, + }, + ], + }, +]; + +runTestCases(testCases); diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json index 4fa8a5b4e7..cea8974a58 100644 --- a/packages/gitbook/package.json +++ b/packages/gitbook/package.json @@ -10,6 +10,7 @@ "typecheck": "tsc --noEmit", "e2e": "playwright test e2e/internal.spec.ts", "e2e-customers": "playwright test e2e/customers.spec.ts", + "e2e-proxy": "playwright test e2e/proxy.spec.ts", "unit": "bun test {src,packages}", "generate": "gitbook-icons ./public/~gitbook/static/icons custom-icons && gitbook-math ./public/~gitbook/static/math", "copy:icons": "gitbook-icons ./public/~gitbook/static/icons", From 5919d57eff8cbcb71c2c9b85f0741e03d8980749 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:40:38 +0530 Subject: [PATCH 06/18] remove skip option --- packages/gitbook/e2e/proxy.spec.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/gitbook/e2e/proxy.spec.ts b/packages/gitbook/e2e/proxy.spec.ts index 7ee2d677bb..ac8f340772 100644 --- a/packages/gitbook/e2e/proxy.spec.ts +++ b/packages/gitbook/e2e/proxy.spec.ts @@ -8,9 +8,6 @@ import { type TestsCase, runTestCases } from './util'; const testCases: TestsCase[] = [ { name: 'Site subdirectory (proxy)', - skip: - process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && - typeof process.env.X_FORWARDED_HOST === 'undefined', contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', tests: [ { @@ -22,9 +19,6 @@ const testCases: TestsCase[] = [ }, { name: 'Site subdirectory (proxy) with VA', - skip: - process.env.ARGOS_BUILD_NAME !== 'v2-vercel' && - typeof process.env.X_FORWARDED_HOST === 'undefined', contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', tests: [ { From 94a3e88e47500c3e3b69e300d68bce4756449c53 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:48:51 +0530 Subject: [PATCH 07/18] add proxy script to package json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index d93f0167ec..fc1b02fa82 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "unit": "turbo run unit", "e2e": "turbo run e2e", "e2e-customers": "turbo run e2e-customers", + "e2e-proxy": "turbo run e2e-proxy", "changeset": "changeset", "changeset-version": "changeset version && bun run format", "release": "turbo run release && changeset publish", From 5ce2decc226939879862b0e78148bc01767f7e05 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:49:31 +0530 Subject: [PATCH 08/18] turbo json --- turbo.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/turbo.json b/turbo.json index 2c627db32f..d7f866f168 100644 --- a/turbo.json +++ b/turbo.json @@ -55,6 +55,11 @@ "e2e-customers": { "dependsOn": ["^e2e-customers"], "env": ["BASE_URL", "SITE_BASE_URL"] + }, + // Run end-to-end tests for customers + "e2e-proxy": { + "dependsOn": ["^e2e-proxy"], + "env": ["BASE_URL", "X_FORWARDED_HOST"] }, // Start the package in development mode "dev": { From 2f54c76101e08579eca7225ae70cbf4b4a5eac5e Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:49:45 +0530 Subject: [PATCH 09/18] update comment --- turbo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo.json b/turbo.json index d7f866f168..bfc59a9bc7 100644 --- a/turbo.json +++ b/turbo.json @@ -56,7 +56,7 @@ "dependsOn": ["^e2e-customers"], "env": ["BASE_URL", "SITE_BASE_URL"] }, - // Run end-to-end tests for customers + // Run end-to-end tests for proxy sites "e2e-proxy": { "dependsOn": ["^e2e-proxy"], "env": ["BASE_URL", "X_FORWARDED_HOST"] From 77a84c2ad4dcf9023e99ff566248dc2ba81234bd Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:51:31 +0530 Subject: [PATCH 10/18] fix format --- turbo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo.json b/turbo.json index bfc59a9bc7..cb83411276 100644 --- a/turbo.json +++ b/turbo.json @@ -56,7 +56,7 @@ "dependsOn": ["^e2e-customers"], "env": ["BASE_URL", "SITE_BASE_URL"] }, - // Run end-to-end tests for proxy sites + // Run end-to-end tests for proxy sites "e2e-proxy": { "dependsOn": ["^e2e-proxy"], "env": ["BASE_URL", "X_FORWARDED_HOST"] From b1fc847bb1c3be5b300af3dbf8b098d8607abe53 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 18:55:07 +0530 Subject: [PATCH 11/18] format --- turbo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo.json b/turbo.json index cb83411276..9e64ea5baf 100644 --- a/turbo.json +++ b/turbo.json @@ -57,7 +57,7 @@ "env": ["BASE_URL", "SITE_BASE_URL"] }, // Run end-to-end tests for proxy sites - "e2e-proxy": { + "e2e-proxy": { "dependsOn": ["^e2e-proxy"], "env": ["BASE_URL", "X_FORWARDED_HOST"] }, From 5eb6f8c85f703978602c120e5c5bb94b5584bd15 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 19:05:55 +0530 Subject: [PATCH 12/18] add logs --- packages/gitbook-v2/src/middleware.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index bc2950c38d..ab2c493b50 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -402,6 +402,8 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { } const xForwardedHost = process.env.X_FORWARDED_HOST ?? request.headers.get('x-forwarded-host'); + console.log('xForwardedHost', xForwardedHost); + console.log('nextUrl', request.nextUrl.toString()); // The x-forwarded-host is set by Vercel for all requests // so we ignore it if the hostname is the same as the instance one. if (xForwardedHost) { From 2f2d67c0fb69889bd5039654f1e4d0c0e337124d Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 20:33:21 +0530 Subject: [PATCH 13/18] try with search param --- packages/gitbook-v2/src/middleware.ts | 6 +++--- packages/gitbook/e2e/proxy.spec.ts | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index ab2c493b50..f1fd5d0c60 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -401,9 +401,9 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { return null; } - const xForwardedHost = process.env.X_FORWARDED_HOST ?? request.headers.get('x-forwarded-host'); - console.log('xForwardedHost', xForwardedHost); - console.log('nextUrl', request.nextUrl.toString()); + const xForwardedHost = + request.nextUrl.searchParams.get('x-forwarded-host') ?? + request.headers.get('x-forwarded-host'); // The x-forwarded-host is set by Vercel for all requests // so we ignore it if the hostname is the same as the instance one. if (xForwardedHost) { diff --git a/packages/gitbook/e2e/proxy.spec.ts b/packages/gitbook/e2e/proxy.spec.ts index ac8f340772..98a5bcd7a5 100644 --- a/packages/gitbook/e2e/proxy.spec.ts +++ b/packages/gitbook/e2e/proxy.spec.ts @@ -1,10 +1,13 @@ import jwt from 'jsonwebtoken'; import { type TestsCase, runTestCases } from './util'; +const xForwardedHostParam = 'x-forwarded-host=proxy.gitbook.site'; + /** * This test suite is designed to run tests for the site subdirectory * feature using a proxy. */ + const testCases: TestsCase[] = [ { name: 'Site subdirectory (proxy)', @@ -12,7 +15,7 @@ const testCases: TestsCase[] = [ tests: [ { name: 'Main', - url: '', + url: `?${xForwardedHostParam}`, fullPage: true, }, ], @@ -35,7 +38,7 @@ const testCases: TestsCase[] = [ expiresIn: '24h', } ); - return `?jwt_token=${token}`; + return `?jwt_token=${token}&${xForwardedHostParam}`; }, fullPage: true, }, From daeb6ca12e408e6dd19b72a3e8a62c7a4c0c3c64 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 20:42:39 +0530 Subject: [PATCH 14/18] lgo --- packages/gitbook-v2/src/middleware.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index f1fd5d0c60..5fca958698 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -404,6 +404,7 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { const xForwardedHost = request.nextUrl.searchParams.get('x-forwarded-host') ?? request.headers.get('x-forwarded-host'); + console.log({ xForwardedHost }); // The x-forwarded-host is set by Vercel for all requests // so we ignore it if the hostname is the same as the instance one. if (xForwardedHost) { From 4b4331fef76ef53c9b6536d7c190db8c5b99a731 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 21:07:27 +0530 Subject: [PATCH 15/18] refactor --- packages/gitbook-v2/src/middleware.ts | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index 5fca958698..653fda3c95 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -396,23 +396,29 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { }; } + // The x-forwarded-host is set by Vercel for all requests + // so we ignore it if the hostname is the same as the instance one. + const xForwardedHost = + request.nextUrl.searchParams.get('x-forwarded-host') ?? + request.headers.get('x-forwarded-host'); + + const forwardedRequest = xForwardedHost + ? appendQueryParams( + new URL(`https://${xForwardedHost}${request.nextUrl.pathname}`), + request.nextUrl.searchParams + ) + : null; + + const isProxy = forwardedRequest ? isProxyRequest(forwardedRequest) : false; + // Skip other requests to main hosts - if (isMainHost || isAssetsHost) { + if ((isMainHost || isAssetsHost) && !isProxy) { return null; } - const xForwardedHost = - request.nextUrl.searchParams.get('x-forwarded-host') ?? - request.headers.get('x-forwarded-host'); - console.log({ xForwardedHost }); - // The x-forwarded-host is set by Vercel for all requests - // so we ignore it if the hostname is the same as the instance one. - if (xForwardedHost) { + if (forwardedRequest) { return { - url: appendQueryParams( - new URL(`https://${xForwardedHost}${request.nextUrl.pathname}`), - request.nextUrl.searchParams - ), + url: forwardedRequest, mode: 'url-host', }; } From 584eeab793c30864e22087f52491cfc38c3d417a Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 21:57:32 +0530 Subject: [PATCH 16/18] Revert "refactor" This reverts commit 4b4331fef76ef53c9b6536d7c190db8c5b99a731. --- packages/gitbook-v2/src/middleware.ts | 30 +++++++++++---------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index 653fda3c95..5fca958698 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -396,29 +396,23 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { }; } - // The x-forwarded-host is set by Vercel for all requests - // so we ignore it if the hostname is the same as the instance one. - const xForwardedHost = - request.nextUrl.searchParams.get('x-forwarded-host') ?? - request.headers.get('x-forwarded-host'); - - const forwardedRequest = xForwardedHost - ? appendQueryParams( - new URL(`https://${xForwardedHost}${request.nextUrl.pathname}`), - request.nextUrl.searchParams - ) - : null; - - const isProxy = forwardedRequest ? isProxyRequest(forwardedRequest) : false; - // Skip other requests to main hosts - if ((isMainHost || isAssetsHost) && !isProxy) { + if (isMainHost || isAssetsHost) { return null; } - if (forwardedRequest) { + const xForwardedHost = + request.nextUrl.searchParams.get('x-forwarded-host') ?? + request.headers.get('x-forwarded-host'); + console.log({ xForwardedHost }); + // The x-forwarded-host is set by Vercel for all requests + // so we ignore it if the hostname is the same as the instance one. + if (xForwardedHost) { return { - url: forwardedRequest, + url: appendQueryParams( + new URL(`https://${xForwardedHost}${request.nextUrl.pathname}`), + request.nextUrl.searchParams + ), mode: 'url-host', }; } From f6155d21adeca8207de949bde5d9ed49654072a1 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 23:23:28 +0530 Subject: [PATCH 17/18] refactor --- .github/workflows/deploy-preview.yaml | 21 ---------- package.json | 1 - packages/gitbook-v2/src/lib/data/index.ts | 1 + .../gitbook-v2/src/lib/data/proxy.test.ts | 21 ++++++++++ .../gitbook-v2/src/lib/data/visitor.test.ts | 41 +++++++++++++++++++ packages/gitbook-v2/src/lib/data/visitor.ts | 19 +++++++++ packages/gitbook-v2/src/middleware.ts | 17 ++------ packages/gitbook/e2e/internal.spec.ts | 37 +++++++++++++++++ packages/gitbook/package.json | 1 - turbo.json | 5 --- 10 files changed, 122 insertions(+), 42 deletions(-) create mode 100644 packages/gitbook-v2/src/lib/data/proxy.test.ts create mode 100644 packages/gitbook-v2/src/lib/data/visitor.test.ts create mode 100644 packages/gitbook-v2/src/lib/data/visitor.ts diff --git a/.github/workflows/deploy-preview.yaml b/.github/workflows/deploy-preview.yaml index 4504f2a74d..013815c58e 100644 --- a/.github/workflows/deploy-preview.yaml +++ b/.github/workflows/deploy-preview.yaml @@ -187,27 +187,6 @@ jobs: SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/ ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} ARGOS_BUILD_NAME: 'v2-vercel' - visual-testing-proxy-v2-vercel: - runs-on: ubuntu-latest - name: Visual Testing v2 (Proxy) - needs: deploy-v2-vercel - timeout-minutes: 10 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Bun - uses: ./.github/composite/setup-bun - - name: Install dependencies - run: bun install --frozen-lockfile - - name: Setup Playwright - uses: ./.github/actions/setup-playwright - - name: Run Playwright tests - run: bun e2e-proxy - env: - BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }} - ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }} - ARGOS_BUILD_NAME: 'v2-vercel' - X_FORWARDED_HOST: 'proxy.gitbook.site' visual-testing-customers-v1: runs-on: ubuntu-latest name: Visual Testing Customers v1 diff --git a/package.json b/package.json index fc1b02fa82..d93f0167ec 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "unit": "turbo run unit", "e2e": "turbo run e2e", "e2e-customers": "turbo run e2e-customers", - "e2e-proxy": "turbo run e2e-proxy", "changeset": "changeset", "changeset-version": "changeset version && bun run format", "release": "turbo run release && changeset publish", diff --git a/packages/gitbook-v2/src/lib/data/index.ts b/packages/gitbook-v2/src/lib/data/index.ts index b50f7e127b..d79049684a 100644 --- a/packages/gitbook-v2/src/lib/data/index.ts +++ b/packages/gitbook-v2/src/lib/data/index.ts @@ -5,3 +5,4 @@ export * from './urls'; export * from './errors'; export * from './lookup'; export * from './proxy'; +export * from './visitor'; diff --git a/packages/gitbook-v2/src/lib/data/proxy.test.ts b/packages/gitbook-v2/src/lib/data/proxy.test.ts new file mode 100644 index 0000000000..caf7505554 --- /dev/null +++ b/packages/gitbook-v2/src/lib/data/proxy.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'bun:test'; +import { getProxyRequestIdentifier, isProxyRequest } from './proxy'; + +describe('isProxyRequest', () => { + it('should return true for proxy requests', () => { + const proxyRequestURL = new URL('https://proxy.gitbook.site/sites/site_foo/hello/world'); + expect(isProxyRequest(proxyRequestURL)).toBe(true); + }); + + it('should return false for non-proxy requests', () => { + const nonProxyRequestURL = new URL('https://example.com/docs/foo/hello/world'); + expect(isProxyRequest(nonProxyRequestURL)).toBe(false); + }); +}); + +describe('getProxyRequestIdentifier', () => { + it('should return the correct identifier for proxy requests', () => { + const proxyRequestURL = new URL('https://proxy.gitbook.site/sites/site_foo/hello/world'); + expect(getProxyRequestIdentifier(proxyRequestURL)).toBe('sites/site_foo'); + }); +}); diff --git a/packages/gitbook-v2/src/lib/data/visitor.test.ts b/packages/gitbook-v2/src/lib/data/visitor.test.ts new file mode 100644 index 0000000000..373dcbc473 --- /dev/null +++ b/packages/gitbook-v2/src/lib/data/visitor.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from 'bun:test'; +import { getVisitorAuthBasePath } from './visitor'; + +describe('getVisitorAuthBasePath', () => { + it('should return the correct base path for proxy requests', () => { + expect( + getVisitorAuthBasePath( + new URL('https://proxy.gitbook.site/sites/site_foo/hello/world'), + { + site: 'site_foo', + siteSpace: 'sitesp_foo', + basePath: '/foo', + siteBasePath: '/foo', + organization: 'org_foo', + space: 'space_foo', + pathname: '/hello/world', + complete: false, + apiToken: 'api_token_foo', + canonicalUrl: 'https://example.com/docs/foo/hello/world', + } + ) + ).toBe('/sites/site_foo/'); + }); + + it('should return the correct base path for non-proxy requests', () => { + expect( + getVisitorAuthBasePath(new URL('https://example.com/docs/foo/hello/world'), { + site: 'site_foo', + siteSpace: 'sitesp_foo', + basePath: '/foo/', + siteBasePath: '/foo/', + organization: 'org_foo', + space: 'space_foo', + pathname: '/hello/world', + complete: false, + apiToken: 'api_token_foo', + canonicalUrl: 'https://example.com/docs/foo/hello/world', + }) + ).toBe('/foo/'); + }); +}); diff --git a/packages/gitbook-v2/src/lib/data/visitor.ts b/packages/gitbook-v2/src/lib/data/visitor.ts new file mode 100644 index 0000000000..f93f0afe87 --- /dev/null +++ b/packages/gitbook-v2/src/lib/data/visitor.ts @@ -0,0 +1,19 @@ +import { withLeadingSlash, withTrailingSlash } from '@/lib/paths'; +import type { PublishedSiteContent } from '@gitbook/api'; +import { getProxyRequestIdentifier, isProxyRequest } from './proxy'; + +/** + * Get the appropriate base path for the visitor authentication cookie. + */ +export function getVisitorAuthBasePath( + siteRequestURL: URL, + siteURLData: PublishedSiteContent +): string { + // The siteRequestURL for proxy requests is of the form `https://proxy.gitbook.com/site/siteId/...` + // In such cases, we should not use the resolved siteBasePath for the cookie because for subsequent requests + // we will not have the siteBasePath in the request URL in order to retrieve the cookie. So we use the + // proxy identifier instead. + return isProxyRequest(siteRequestURL) + ? withLeadingSlash(withTrailingSlash(getProxyRequestIdentifier(siteRequestURL))) + : siteURLData.siteBasePath; +} diff --git a/packages/gitbook-v2/src/middleware.ts b/packages/gitbook-v2/src/middleware.ts index 5fca958698..a41d868074 100644 --- a/packages/gitbook-v2/src/middleware.ts +++ b/packages/gitbook-v2/src/middleware.ts @@ -16,9 +16,8 @@ import { import { serveResizedImage } from '@/routes/image'; import { DataFetcherError, - getProxyRequestIdentifier, getPublishedContentByURL, - isProxyRequest, + getVisitorAuthBasePath, normalizeURL, throwIfDataError, } from '@v2/lib/data'; @@ -26,7 +25,6 @@ import { isGitBookAssetsHostURL, isGitBookHostURL } from '@v2/lib/env'; import { getImageResizingContextId } from '@v2/lib/images'; import { MiddlewareHeaders } from '@v2/lib/middleware'; import type { SiteURLData } from './lib/context'; - export const config = { matcher: [ '/((?!_next/static|_next/image|~gitbook/static|~gitbook/revalidate|~gitbook/monitoring|~scalar/proxy).*)', @@ -141,13 +139,7 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) { cookies.push( ...getResponseCookiesForVisitorAuth( - // The siteRequestURL for proxy requests is of the form `https://proxy.gitbook.com/site/siteId/...` - // In such cases, we should not use the resolved siteBasePath for the cookie because for subsequent requests - // we will not have the siteBasePath in the request URL in order to retrieve the cookie. So we use the - // proxy identifier instead. - isProxyRequest(siteRequestURL) - ? getProxyRequestIdentifier(siteRequestURL) - : siteURLData.siteBasePath, + getVisitorAuthBasePath(siteRequestURL, siteURLData), visitorToken ) ); @@ -401,10 +393,7 @@ function getSiteURLFromRequest(request: NextRequest): URLWithMode | null { return null; } - const xForwardedHost = - request.nextUrl.searchParams.get('x-forwarded-host') ?? - request.headers.get('x-forwarded-host'); - console.log({ xForwardedHost }); + const xForwardedHost = request.headers.get('x-forwarded-host'); // The x-forwarded-host is set by Vercel for all requests // so we ignore it if the hostname is the same as the instance one. if (xForwardedHost) { diff --git a/packages/gitbook/e2e/internal.spec.ts b/packages/gitbook/e2e/internal.spec.ts index 4b244a0c4a..1a15c36021 100644 --- a/packages/gitbook/e2e/internal.spec.ts +++ b/packages/gitbook/e2e/internal.spec.ts @@ -419,6 +419,43 @@ const testCases: TestsCase[] = [ }, ], }, + { + name: 'Site subdirectory (proxy)', + skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel', + contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', + tests: [ + { + name: 'Main', + url: '', + fullPage: true, + }, + ], + }, + { + name: 'Site subdirectory (proxy) with VA', + skip: process.env.ARGOS_BUILD_NAME !== 'v2-vercel', + contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', + tests: [ + { + name: 'Main', + url: () => { + const privateKey = + 'rqSfA6x7eAKx1qDRCDq9aCXwivpUvQ8YkXeDdFvCCUa9QchIcM7pF1iJ4o7AGOU49spmOWjKoIPtX0pVUVQ81w=='; + const token = jwt.sign( + { + name: 'gitbook-open-tests', + }, + privateKey, + { + expiresIn: '24h', + } + ); + return `?jwt_token=${token}`; + }, + fullPage: true, + }, + ], + }, { name: 'Content tests', contentBaseURL: 'https://gitbook.gitbook.io/test-gitbook-open/', diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json index cea8974a58..4fa8a5b4e7 100644 --- a/packages/gitbook/package.json +++ b/packages/gitbook/package.json @@ -10,7 +10,6 @@ "typecheck": "tsc --noEmit", "e2e": "playwright test e2e/internal.spec.ts", "e2e-customers": "playwright test e2e/customers.spec.ts", - "e2e-proxy": "playwright test e2e/proxy.spec.ts", "unit": "bun test {src,packages}", "generate": "gitbook-icons ./public/~gitbook/static/icons custom-icons && gitbook-math ./public/~gitbook/static/math", "copy:icons": "gitbook-icons ./public/~gitbook/static/icons", diff --git a/turbo.json b/turbo.json index 9e64ea5baf..2c627db32f 100644 --- a/turbo.json +++ b/turbo.json @@ -56,11 +56,6 @@ "dependsOn": ["^e2e-customers"], "env": ["BASE_URL", "SITE_BASE_URL"] }, - // Run end-to-end tests for proxy sites - "e2e-proxy": { - "dependsOn": ["^e2e-proxy"], - "env": ["BASE_URL", "X_FORWARDED_HOST"] - }, // Start the package in development mode "dev": { "persistent": true, From 28aec4813f482b0418310632f0e2806c6e56ca78 Mon Sep 17 00:00:00 2001 From: taranvohra Date: Tue, 8 Apr 2025 23:26:31 +0530 Subject: [PATCH 18/18] remove spec --- packages/gitbook/e2e/proxy.spec.ts | 49 ------------------------------ 1 file changed, 49 deletions(-) delete mode 100644 packages/gitbook/e2e/proxy.spec.ts diff --git a/packages/gitbook/e2e/proxy.spec.ts b/packages/gitbook/e2e/proxy.spec.ts deleted file mode 100644 index 98a5bcd7a5..0000000000 --- a/packages/gitbook/e2e/proxy.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import jwt from 'jsonwebtoken'; -import { type TestsCase, runTestCases } from './util'; - -const xForwardedHostParam = 'x-forwarded-host=proxy.gitbook.site'; - -/** - * This test suite is designed to run tests for the site subdirectory - * feature using a proxy. - */ - -const testCases: TestsCase[] = [ - { - name: 'Site subdirectory (proxy)', - contentBaseURL: 'https://nextjs-gbo-proxy.vercel.app/documentation/', - tests: [ - { - name: 'Main', - url: `?${xForwardedHostParam}`, - fullPage: true, - }, - ], - }, - { - name: 'Site subdirectory (proxy) with VA', - contentBaseURL: 'https://nextjs-gbo-proxy-va.vercel.app/va/docs/', - tests: [ - { - name: 'Main', - url: () => { - const privateKey = - 'rqSfA6x7eAKx1qDRCDq9aCXwivpUvQ8YkXeDdFvCCUa9QchIcM7pF1iJ4o7AGOU49spmOWjKoIPtX0pVUVQ81w=='; - const token = jwt.sign( - { - name: 'gitbook-open-tests', - }, - privateKey, - { - expiresIn: '24h', - } - ); - return `?jwt_token=${token}&${xForwardedHostParam}`; - }, - fullPage: true, - }, - ], - }, -]; - -runTestCases(testCases);