The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { Hyperdrive } from "@cloudflare/workers-types"; |
| 2 | import { Client } from "pg"; |
| 3 | |
| 4 | /** |
| 5 | * Async Worker that binds the Access-protected Hyperdrive via |
| 6 | * `env: { HD: connection }` and runs a query through it. |
| 7 | */ |
| 8 | export default { |
| 9 | async fetch(_request: Request, env: { HD: Hyperdrive }): Promise<Response> { |
| 10 | const client = new Client({ connectionString: env.HD.connectionString }); |
| 11 | try { |
| 12 | await client.connect(); |
| 13 | const result = await client.query("select 'through-access' as via"); |
| 14 | return Response.json(result.rows[0]); |
| 15 | } catch (error) { |
| 16 | return new Response(String(error), { status: 500 }); |
| 17 | } finally { |
| 18 | await client.end().catch(() => {}); |
| 19 | } |
| 20 | }, |
| 21 | }; |