The best way to control Claude Code, Codex and more from any computer or phone

main
ts 29 lines 1.03 KB
Raw
1 // Alchemy modifications are licensed under Apache-2.0.
2 // This file includes third-party code; see /THIRD_PARTY_LICENSES.md.
3
4 interface Env {
5 __VITE_MIDDLEWARE__: Fetcher;
6 ASSET_WORKER: Fetcher;
7 }
8
9 /** Set by the Vite middleware handler when no Vite middleware served the request. */
10 const VITE_MISS_HEADER = "x-alchemy-vite-asset-miss";
11
12 /**
13 * The dev `ASSETS` binding a Worker calls.
14 *
15 * Mirrors `@cloudflare/vite-plugin`'s dev wiring, which binds `ASSETS` to the
16 * Vite dev server's middleware: anything Vite serves (source files a Worker
17 * imports by URL, `/@fs/` dependency files, `public/`) resolves as it does in
18 * the browser. Requests Vite doesn't serve fall back to the asset worker,
19 * which applies the HTML handling and not-found rules.
20 */
21 export default {
22 async fetch(request: Request, env: Env): Promise<Response> {
23 const response = await env.__VITE_MIDDLEWARE__.fetch(request.clone());
24 if (response.headers.has(VITE_MISS_HEADER)) {
25 return env.ASSET_WORKER.fetch(request);
26 }
27 return response;
28 },
29 };