@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, 06:00 UTC

main
ts 38 lines 1.24 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 * as Redacted from "effect/Redacted";
6 import { ApiKey } from "./ApiKey.ts";
7
8 export default class Api extends Cloudflare.Worker<Api>()(
9 "Api",
10 {
11 main: import.meta.url,
12 },
13 Effect.gen(function* () {
14 const apiKey = yield* Cloudflare.SecretsStore.ReadSecret(ApiKey);
15
16 return {
17 fetch: Effect.gen(function* () {
18 const request = yield* HttpServerRequest;
19
20 if (request.url === "/secret") {
21 const value = Redacted.value(yield* apiKey);
22 const masked = value.slice(0, 4) + "****";
23 return HttpServerResponse.text(`Secret (masked): ${masked}`);
24 }
25
26 return HttpServerResponse.text("Hello from Cloudflare Secrets Store example!");
27 }).pipe(
28 Effect.catchTag("SecretError", (err) =>
29 Effect.succeed(
30 HttpServerResponse.text(`Failed to read secret: ${err.message}`, {
31 status: 500,
32 }),
33 ),
34 ),
35 ),
36 };
37 }).pipe(Effect.provide(Cloudflare.SecretsStore.ReadSecretBinding)),
38 ) {}