The best way to control Claude Code, Codex and more from any computer or phone
| 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 { AccessOriginConnection } from "./access-origin.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Effect Worker that binds the Access-protected Hyperdrive through |
| 9 | * `Cloudflare.Hyperdrive.Connect` and runs a query through it, so a 200 |
| 10 | * proves the whole path: Hyperdrive → Access → Tunnel → Postgres. |
| 11 | */ |
| 12 | export default class HyperdriveAccessEffectWorker extends Cloudflare.Worker<HyperdriveAccessEffectWorker>()( |
| 13 | "HyperdriveAccessEffectWorker", |
| 14 | { main: import.meta.url }, |
| 15 | Effect.gen(function* () { |
| 16 | const connection = yield* AccessOriginConnection; |
| 17 | const hd = yield* Cloudflare.Hyperdrive.Connect(connection); |
| 18 | const sql = yield* SQL.Postgres({ url: hd.connectionString }); |
| 19 | return { |
| 20 | fetch: sql`select 'through-access' 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 | ) {} |