@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

main
ts 35 lines 1.35 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import { HttpServerRequest } from "effect/http/HttpServerRequest";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5 import { lookupConfigName } from "./lookup.ts";
6 import { connectionRoutes } from "./routes.ts";
7
8 /**
9 * An existing Hyperdrive configuration looked up by name — never managed by
10 * the stack.
11 */
12 export const LookupHyperdrive = Cloudflare.Hyperdrive.lookup("HyperdriveLookup", {
13 name: lookupConfigName("live"),
14 });
15
16 /**
17 * Effect-native Worker binding the looked-up configuration through
18 * `Cloudflare.Hyperdrive.Connect` and exposing the client over the shared
19 * {@link connectionRoutes}.
20 */
21 export default class HyperdriveLookupEffectWorker extends Cloudflare.Worker<HyperdriveLookupEffectWorker>()(
22 "HyperdriveLookupEffectWorker",
23 { main: import.meta.url },
24 Effect.gen(function* () {
25 const hd = yield* Cloudflare.Hyperdrive.Connect(LookupHyperdrive);
26 return {
27 fetch: Effect.gen(function* () {
28 const request = yield* HttpServerRequest;
29 const url = new URL(request.url, "http://x");
30 const handled = yield* connectionRoutes(hd, url);
31 return handled ?? HttpServerResponse.text("Not Found", { status: 404 });
32 }),
33 };
34 }).pipe(Effect.provide(Cloudflare.Hyperdrive.ConnectBinding)),
35 ) {}