@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 43 lines 1.35 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Effect from "effect/Effect";
3 import * as HttpClientRequest from "effect/http/HttpClientRequest";
4 import { NeonHostProject } from "./db.ts";
5
6 class NeonHostContainer extends Cloudflare.Container<NeonHostContainer>()(
7 "NeonHostContainer",
8 Effect.gen(function* () {
9 const project = yield* NeonHostProject;
10 return {
11 context: `${import.meta.dirname}/../sqlreach/context`,
12 env: {
13 DATABASE_URL: project.pooledConnectionUri,
14 },
15 observability: { logs: { enabled: true } },
16 };
17 }),
18 ) {}
19
20 export class NeonHostContainerObject extends Cloudflare.DurableObject<NeonHostContainerObject>()(
21 "NeonHostContainerObject",
22 Effect.gen(function* () {
23 const container = yield* NeonHostContainer;
24
25 return Effect.gen(function* () {
26 // Starting is idempotent: a no-op once the container is running.
27 const start = container.start({ enableInternet: true });
28 const { fetch } = yield* container.getTcpPort(8080);
29
30 const get = (path: string) =>
31 Effect.gen(function* () {
32 yield* start;
33 const response = yield* fetch(HttpClientRequest.get(`http://container${path}`));
34 return yield* response.text;
35 });
36
37 return {
38 getEnv: () => get("/env"),
39 getProbe: () => get("/probe"),
40 };
41 });
42 }),
43 ) {}