@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, 07:15 UTC

main
ts 45 lines 1.71 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as Redacted from "effect/Redacted";
4
5 /**
6 * A private Hyperdrive origin reached through Workers VPC: a local Postgres
7 * exposed as a TCP VPC Service over a Cloudflare Tunnel. `cloudflared` runs
8 * on the test machine with the tunnel's token (see the Workers VPC test in
9 * `Hyperdrive.test.ts`), standing in for a connector inside a private
10 * network such as an AWS VPC.
11 */
12 export const VPC_ORIGIN_PORT = 15433;
13 export const VPC_ORIGIN_PASSWORD = "alchemy-vpc-origin";
14
15 /** Tunnel whose connector reaches the private network. */
16 export const VpcOriginTunnel = Cloudflare.Tunnel.Tunnel("HyperdriveVpcTunnel", {
17 ingress: [{ service: "http_status:404" }],
18 });
19
20 /** TCP VPC Service that routes to Postgres through the tunnel. */
21 export const VpcOriginService = Effect.gen(function* () {
22 const tunnel = yield* VpcOriginTunnel;
23 return yield* Cloudflare.Connectivity.DirectoryService("HyperdriveVpcService", {
24 type: "tcp",
25 tcpPort: VPC_ORIGIN_PORT,
26 appProtocol: "postgresql",
27 // The test Postgres serves the image's self-signed snakeoil cert.
28 tlsSettings: { certVerificationMode: "disabled" },
29 host: { ipv4: "127.0.0.1", network: { tunnelId: tunnel.tunnelId } },
30 });
31 });
32
33 /** The Hyperdrive Connection that egresses through the VPC Service. */
34 export const VpcOriginConnection = Effect.gen(function* () {
35 const service = yield* VpcOriginService;
36 return yield* Cloudflare.Hyperdrive.Connection("HyperdriveVpcConnection", {
37 origin: {
38 scheme: "postgres",
39 serviceId: service.serviceId,
40 database: "postgres",
41 user: "postgres",
42 password: Redacted.make(VPC_ORIGIN_PASSWORD),
43 },
44 });
45 });