1import { createFileRoute } from "@tanstack/react-router";
2import { env } from "cloudflare:workers";
3
4/**
5 * Same-origin proxy for the browser's `AtomRpc` client. The browser can't use a
6 * Cloudflare service binding directly, so the `AtomRpc` protocol points at this
7 * `/rpc` route and we forward the request body to the private `BACKEND` worker
8 * over the service binding. This keeps the backend off the public internet and
9 * avoids CORS.
10 */
11export const Route = createFileRoute("/rpc")({
12 server: {
13 handlers: {
14 ANY: async ({ request }) => {
15 return await env.BACKEND.fetch(request);
16 },
17 },
18 },
19});