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

devProxy.ts

28 lines1.1 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.
17 */
18export const DEV_PROXIED_ORIGIN_PRESERVING_PREFIXES: ReadonlySet<string> = new Set([
19 "/oauth",
20 "/.well-known",
21 "/mcp",
22]);
23​
24export function isDevProxiedPath(pathname: string): boolean {
25 return DEV_PROXIED_PATH_PREFIXES.some(
26 (prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`),
27 );