@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

Syncing…

main
ts 45 lines 1.55 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 { App } from "./app.ts";
6
7 /**
8 * Effect-native Worker fixture for the Cloudflare Flagship binding.
9 * `Flagship.ReadFlags(App)` during init attaches the binding to this Worker
10 * (registering the app resource with the stack) and resolves to the runtime
11 * client.
12 */
13 export default class FlagshipEffectWorker extends Cloudflare.Worker<FlagshipEffectWorker>()(
14 "FlagshipEffectWorker",
15 {
16 main: import.meta.url,
17 },
18 Effect.gen(function* () {
19 const flags = yield* Cloudflare.Flagship.ReadFlags(App);
20
21 return {
22 fetch: Effect.gen(function* () {
23 const request = yield* HttpServerRequest;
24
25 if (request.url.startsWith("/bool")) {
26 const enabled = yield* flags
27 .getBooleanValue("test-flag", false, { userId: "user-42" })
28 .pipe(Effect.orDie);
29 return yield* HttpServerResponse.json({ mode: "effect", enabled });
30 }
31
32 if (request.url.startsWith("/details")) {
33 const details = yield* flags
34 .getStringDetails("nonexistent-flag", "fallback", {
35 userId: "user-42",
36 })
37 .pipe(Effect.orDie);
38 return yield* HttpServerResponse.json({ mode: "effect", details });
39 }
40
41 return HttpServerResponse.text("ok");
42 }),
43 };
44 }).pipe(Effect.provide(Cloudflare.Flagship.ReadFlagsBinding)),
45 ) {}