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

main
ts 38 lines 1.28 KB
Raw
1 import { CloudflareD1 } from "@alchemy.run/better-auth/CloudflareD1";
2 import * as Cloudflare from "@alchemy.run/cloudflare";
3 import * as Git from "@alchemy.run/git";
4 import * as Effect from "effect/Effect";
5 /**
6 * The Worker that serves the API: Better Auth's routes under `/api/auth`,
7 * the git server for everything else. `src/worker.ts` fronts it on the
8 * website's origin.
9 */
10 import * as HttpRouter from "effect/http/HttpRouter";
11 import { HttpServerRequest } from "effect/http/HttpServerRequest";
12 import * as Layer from "effect/Layer";
13 import { Auth, AuthDb } from "./auth.ts";
14 import { HttpLive } from "./git.ts";
15
16 export default class GitHost extends Cloudflare.Worker<GitHost>()(
17 "GitHost",
18 {
19 main: import.meta.url,
20 ...Git.GIT_WORKER_OPTIONS,
21 observability: { enabled: true },
22 },
23 Effect.gen(function* () {
24 const auth = yield* Auth;
25 const fetch = yield* HttpRouter.toHttpEffect(HttpLive);
26 return {
27 fetch: Effect.scoped(
28 Effect.gen(function* () {
29 const request = yield* HttpServerRequest;
30 if (request.url.startsWith("/api/auth")) return yield* auth.fetch;
31 return yield* fetch;
32 }),
33 ),
34 };
35 }).pipe(
36 Effect.provide(Layer.mergeAll(CloudflareD1(AuthDb), Cloudflare.R2.ReadWriteBucketBinding)),
37 ),
38 ) {}