@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, 04:45 UTC

main
ts 49 lines 1.74 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Output from "alchemy/Output";
3 import * as Effect from "effect/Effect";
4 import { Connector, Tunnel } from "./Connector.ts";
5 import { DB_NAME, DB_USER, Database, DbPassword } from "./Database.ts";
6
7 /**
8 * A TCP VPC Service for the Aurora writer endpoint. `cloudflared` resolves
9 * the hostname with the VPC's DNS, so the private endpoint works as-is.
10 */
11 export const AuroraService = Effect.gen(function* () {
12 const tunnel = yield* Tunnel;
13 const connector = yield* Connector;
14 const db = yield* Database;
15 // Hyperdrive connects to the database when it is created, so the path
16 // must be live first: wait for the writer instance and the connector.
17 const hostname = Output.map(
18 Output.all(db.cluster.endpoint, db.writer.dbInstanceArn, connector.serviceArn),
19 ([endpoint]) => endpoint!,
20 );
21 return yield* Cloudflare.Connectivity.DirectoryService("AuroraService", {
22 type: "tcp",
23 tcpPort: 5432,
24 appProtocol: "postgresql",
25 host: {
26 hostname,
27 resolverNetwork: { tunnelId: tunnel.tunnelId },
28 },
29 // Aurora's certificate is issued by the Amazon RDS CA, which Workers VPC
30 // does not trust yet (custom CAs are not supported). The connection is
31 // still TLS-encrypted.
32 tlsSettings: { certVerificationMode: "disabled" },
33 });
34 });
35
36 /** Hyperdrive egresses through the VPC Service to reach Aurora. */
37 export const Hyperdrive = Effect.gen(function* () {
38 const service = yield* AuroraService;
39 const password = yield* DbPassword;
40 return yield* Cloudflare.Hyperdrive.Connection("Hyperdrive", {
41 origin: {
42 scheme: "postgres",
43 serviceId: service.serviceId,
44 database: DB_NAME,
45 user: DB_USER,
46 password: password.text,
47 },
48 });
49 });