@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 24 lines 1.02 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 { TestNamespace } from "./namespace.ts";
6 import { readRoutes } from "./read-routes.ts";
7
8 /** Read-only access via a scoped HTTP API token (`ReadNamespaceHttp`). */
9 export default class KVReadHttpWorker extends Cloudflare.Worker<KVReadHttpWorker>()(
10 "KVReadHttpWorker",
11 { main: import.meta.url },
12 Effect.gen(function* () {
13 const namespace = yield* TestNamespace;
14 const kv = yield* Cloudflare.KV.ReadNamespace(namespace);
15 return {
16 fetch: Effect.gen(function* () {
17 const request = yield* HttpServerRequest;
18 const url = new URL(request.url, "http://x");
19 const handled = yield* readRoutes(kv, url);
20 return handled ?? HttpServerResponse.text("Not Found", { status: 404 });
21 }),
22 };
23 }).pipe(Effect.provide(Cloudflare.KV.ReadNamespaceHttp)),
24 ) {}