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

main
ts 28 lines 1.19 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as SQL from "@alchemy.run/sql/Postgres";
3 import * as Effect from "effect/Effect";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5 import { VpcOriginConnection } from "./vpc-origin.ts";
6
7 /**
8 * Effect Worker that binds the Workers VPC Hyperdrive through
9 * `Cloudflare.Hyperdrive.Connect` and runs a query through it, so a 200
10 * proves the whole path: Hyperdrive → VPC Service → Tunnel → Postgres.
11 */
12 export default class HyperdriveVpcEffectWorker extends Cloudflare.Worker<HyperdriveVpcEffectWorker>()(
13 "HyperdriveVpcEffectWorker",
14 { main: import.meta.url },
15 Effect.gen(function* () {
16 const connection = yield* VpcOriginConnection;
17 const hd = yield* Cloudflare.Hyperdrive.Connect(connection);
18 const sql = yield* SQL.Postgres({ url: hd.connectionString });
19 return {
20 fetch: sql`select 'through-vpc' as via`.pipe(
21 Effect.flatMap((rows) => HttpServerResponse.json(rows[0])),
22 Effect.catchCause((cause) =>
23 Effect.succeed(HttpServerResponse.text(String(cause), { status: 500 })),
24 ),
25 ),
26 };
27 }).pipe(Effect.provide(Cloudflare.Hyperdrive.ConnectBinding)),
28 ) {}