Skip to content

feat(cloudflare): federate Vite Workers through the local edge - #3778

Open
RedPhortex wants to merge 1 commit into
alchemy-run:mainfrom
RedPhortex:feat/cloudflare-vite-local-edge
Open

RedPhortex wants to merge 1 commit into
alchemy-run:mainfrom
RedPhortex:feat/cloudflare-vite-local-edge

Conversation

@RedPhortex

Copy link
Copy Markdown

Vite Workers now join the local zone-route router under alchemy dev: a Vite site with a domain and routes serves matched paths from the owning Worker and everything else, including assets and HMR WebSockets, from its dev server.

const api = yield* Cloudflare.Worker("Api", {
  main: "./api.ts",
  routes: [{ pattern: "app.example.com/api/*", zoneName: "example.com" }],
});
const app = yield* Cloudflare.Website.Vite("App", {
  domain: "app.example.com",
});
  • Each dev server gets a private origin proxy, registered with registerHttpServer() as <name>-vite-edge and mapped with LocalEdge.setTarget. The public proxy stays separate, so a routed request cannot loop back through the public URL.
  • The origin parks requests while the dev server restarts. An interrupted start keeps them parked instead of failing them.
  • The site's domain and literal route hosts (.example.com for *.example.com) are added to Vite's allowedHosts.
  • An HTTPS dev server cannot sit behind the plain-HTTP router. Routed requests fail with a message naming server.https, and the Worker's own dev URL keeps serving.
  • Source-provided dev servers (devMode: "server") keep their proxy pointed straight at the dev server.

Known limits, documented on Website.Vite: Vite's host check rejects suffix wildcards (*example.com), a bare * host, and standalone Workers.WorkerRoute hostnames unless the app adds them to server.allowedHosts.

🤖 Generated with Claude Code

Vite Workers now take part in the local zone-route router under `alchemy
dev`.

- Bridge each Vite dev server to the edge with `registerHttpServer()`
under
  `<name>-vite-edge`, mapped with `LocalEdge.setTarget`
- Keep a private origin proxy apart from the public proxy so routed
  requests cannot loop back through the public URL
- Park requests on the origin while the dev server restarts
- Add the domain and literal/`*.` route hosts to Vite's `allowedHosts`
- Fail routed requests clearly when the dev server serves HTTPS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant