| 57 | * forwarding headers, preserving method, body, path, and query. |
| 58 | */ |
| 59 | export const buildDocsUpstream = (request: Request): Request => { |
| 60 | const url = new URL(request.url); |
| 61 | const forwardedHost = url.host; |
| 62 | |
| 63 | url.hostname = DOCS_UPSTREAM_HOST; |
| 64 | url.protocol = "https:"; |
| 65 | url.port = ""; |
| 66 | |
| 67 | const upstream = new Request(url, request); |
| 68 | // Mintlify keys canonical links off the public host; tell it the real one. |
| 69 | upstream.headers.set("X-Forwarded-Host", forwardedHost); |
| 70 | upstream.headers.set("X-Forwarded-Proto", "https"); |
| 71 | // Never leak the executor.sh session cookie to the docs origin. |
| 72 | upstream.headers.delete("cookie"); |
| 73 | return upstream; |
| 74 | }; |
| 75 | |
| 76 | /** Build the upstream request for an already-classified PostHog proxy path. */ |
| 77 | export const buildPosthogUpstream = (request: Request, pathname: string): Request => { |