@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, 06:00 UTC

main
ts 44 lines 1.5 KB
Raw
1 import * as Fly from "@alchemy.run/fly";
2 import * as Effect from "effect/Effect";
3 import * as FileSystem from "effect/FileSystem";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6 import { API_PORT, MARKER, MARKER_FILE, Site, VOLUME_PATH } from "./shared.ts";
7
8 /**
9 * HTTP Service: mounts a per-replica disk, writes a marker, and serves it back.
10 */
11 export default class Api extends Fly.Service<Api>()(
12 "Api",
13 {
14 app: Site,
15 main: import.meta.url,
16 region: "iad",
17 port: API_PORT,
18 guest: { cpuKind: "shared", cpus: 1, memoryMb: 256 },
19 },
20 Effect.gen(function* () {
21 const mount = yield* Fly.MountVolume({ path: VOLUME_PATH, sizeGb: 1 });
22 const fs = yield* FileSystem.FileSystem;
23
24 return {
25 fetch: Effect.gen(function* () {
26 const request = yield* HttpServerRequest;
27 const url = new URL(request.url, "http://service");
28 if (url.pathname === "/health") {
29 return yield* HttpServerResponse.json({
30 ok: true,
31 path: mount.path,
32 });
33 }
34 yield* fs.makeDirectory(mount.path, { recursive: true }).pipe(Effect.orDie);
35 yield* fs.writeFileString(MARKER_FILE, MARKER).pipe(Effect.orDie);
36 const text = yield* fs.readFileString(MARKER_FILE).pipe(Effect.orDie);
37 return yield* HttpServerResponse.json({
38 path: mount.path,
39 text,
40 });
41 }),
42 };
43 }).pipe(Effect.provide(Fly.MountVolumeLive)),
44 ) {}