(request, env, ctx)
| 40 | |
| 41 | export default { |
| 42 | async fetch(request, env, ctx) { |
| 43 | // 1. Sandbox preview-port traffic is routed by hostname, so it gets first |
| 44 | // refusal on every request before any path-based routing. |
| 45 | const proxied = await proxyToSandbox(request, env) |
| 46 | if (proxied) return proxied |
| 47 | |
| 48 | // 2. The agent's own HTTP surface. `agent.worker` is built by the package's |
| 49 | // `createSandboxAgentWorker`, so its `fetch` is always present. |
| 50 | const { pathname } = new URL(request.url) |
| 51 | if (ownedByAgent(pathname) && agent.worker.fetch) { |
| 52 | return agent.worker.fetch(request, env, ctx) |
| 53 | } |
| 54 | |
| 55 | // 3. The TanStack Start app (UI + `/api/*` server routes). Start's handler |
| 56 | // takes the request (its 2nd arg is an SSR-context option, not the Worker |
| 57 | // env); bindings are read ambiently via the Cloudflare Vite plugin. |
| 58 | return handler.fetch(request) |
| 59 | }, |
| 60 | } satisfies ExportedHandler<AppEnv> |
no test coverage detected