| 24 | // guarantees `isDocsPath(pathname)` — we only swap the origin and fix up the |
| 25 | // forwarding headers, preserving method, body, path, and query. |
| 26 | export const buildDocsUpstream = (request: Request): Request => { |
| 27 | const url = new URL(request.url); |
| 28 | const forwardedHost = url.host; |
| 29 | |
| 30 | url.hostname = DOCS_UPSTREAM_HOST; |
| 31 | url.protocol = "https:"; |
| 32 | url.port = ""; |
| 33 | |
| 34 | const upstream = new Request(url, request); |
| 35 | // Mintlify keys canonical links off the public host; tell it the real one. |
| 36 | upstream.headers.set("X-Forwarded-Host", forwardedHost); |
| 37 | upstream.headers.set("X-Forwarded-Proto", "https"); |
| 38 | // Never leak the executor.sh session cookie to the docs origin. |
| 39 | upstream.headers.delete("cookie"); |
| 40 | return upstream; |
| 41 | }; |
| 42 | |
| 43 | export const docsProxyMiddleware = createMiddleware({ type: "request" }).server( |
| 44 | ({ pathname, request, next }) => { |