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

main
ts 36 lines 1.44 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as HttpClientRequest from "effect/http/HttpClientRequest";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5 import * as Redacted from "effect/Redacted";
6 import { LEAF_CERT, LEAF_KEY } from "./certs.ts";
7
8 /** The leaf certificate the Worker presents on its subrequests. */
9 export const FetchCert = Cloudflare.MtlsCertificate.MtlsCertificate("FetchCert", {
10 ca: false,
11 certificates: LEAF_CERT,
12 privateKey: Redacted.make(LEAF_KEY),
13 });
14
15 /**
16 * Effect Worker that binds {@link FetchCert} through
17 * `Cloudflare.MtlsCertificate.Fetch` and sends a request with it, so a 200
18 * proves the binding was attached and the Effect client sends through it.
19 */
20 export default class MtlsFetchWorker extends Cloudflare.Worker<MtlsFetchWorker>()(
21 "MtlsFetchWorker",
22 { main: import.meta.url },
23 Effect.gen(function* () {
24 const fetchWithCert = yield* Cloudflare.MtlsCertificate.Fetch(yield* FetchCert);
25 return {
26 fetch: Effect.gen(function* () {
27 const response = yield* fetchWithCert(HttpClientRequest.get("https://example.com/"));
28 return HttpServerResponse.text(`origin-status:${response.status}`);
29 }).pipe(
30 Effect.catch((error) =>
31 Effect.succeed(HttpServerResponse.text(String(error), { status: 500 })),
32 ),
33 ),
34 };
35 }).pipe(Effect.provide(Cloudflare.MtlsCertificate.FetchBinding)),
36 ) {}