Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

devProxy.ts

31 lines1.3 KB

1/**
2 * Backend paths the web dev server proxies in single-origin browser dev.
3 *
4 * Two consumers must agree on this list: the Vite proxy map
5 * (apps/web/vite.config.ts) that forwards these to the backend, and the
6 * server's dev catch-all (apps/server/src/http.ts) that 404s them instead of
7 * redirecting back to Vite. Drift is silent and nasty in both directions — a
8 * prefix only Vite knows gets answered with index.html; a prefix only the
9 * server knows redirect-loops through the proxy.
10 */
11export const DEV_PROXIED_PATH_PREFIXES = ["/api", "/oauth", "/.well-known", "/ws", "/mcp"] as const;
12​
13/**
14 * Prefixes the proxy must forward with the browser's own Host. MCP OAuth
15 * derives its issuer and resource URLs from the request, and a client
16 * rejects metadata naming a different origin than the one it fetched. The
17 * server accepts a cookie session on `/ws` only when the page's Origin matches
18 * the Host it sees, so whatever origin the page was opened on keeps working.
19 */
20export const DEV_PROXIED_ORIGIN_PRESERVING_PREFIXES: ReadonlySet<string> = new Set([
21 "/oauth",
22 "/.well-known",
23 "/mcp",
24 "/ws",
25]);
26​
27export function isDevProxiedPath(pathname: string): boolean {
28 return DEV_PROXIED_PATH_PREFIXES.some(
29 (prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`),
30 );