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

devProxy.ts

28 lines1.1 KB

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