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

main
ts 48 lines 1.58 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Drizzle from "@alchemy.run/drizzle";
3 import * as Neon from "@alchemy.run/neon";
4 import * as Alchemy from "alchemy";
5 import * as Effect from "effect/Effect";
6 import * as Layer from "effect/Layer";
7 import Backend from "./src/backend/api.ts";
8 import { Hyperdrive, NeonDatabase } from "./src/backend/database.ts";
9
10 /**
11 * The TanStack Start frontend. Deployed as a Cloudflare Worker + static assets
12 * by `Cloudflare.Website.Vite`. The `Backend` RPC worker is injected as a private
13 * `BACKEND` service binding; the `/rpc` server route proxies the browser's
14 * `AtomRpc` traffic to it.
15 */
16 export class Website extends Cloudflare.Website.Vite<Website>()("Website", {
17 compatibility: {
18 // Node.js compatibility is supplied by Alchemy's 2026-08-31 default.
19 flags: ["enable_request_signal"],
20 },
21 env: {
22 BACKEND: Backend,
23 },
24 }) {}
25
26 export type WebsiteEnv = Cloudflare.InferEnv<typeof Website>;
27
28 export default Alchemy.Stack(
29 "CloudflareTanstackRpcDrizzleExample",
30 {
31 providers: Layer.mergeAll(Cloudflare.providers(), Drizzle.providers(), Neon.providers()),
32 state: Alchemy.localState(),
33 },
34 Effect.gen(function* () {
35 const { branch } = yield* NeonDatabase;
36 const hd = yield* Hyperdrive;
37 const website = yield* Website;
38
39 // Backend does not need to be yielded here.
40 // The service binding adds it to the resource graph automatically, and there's no direct URL.
41
42 return {
43 websiteUrl: website.url.as<string>(),
44 branchId: branch.branchId,
45 hyperdriveId: hd.hyperdriveId,
46 };
47 }),
48 );