@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 42 lines 1.26 KB
Raw
1 import * as Fly from "@alchemy.run/fly";
2 import * as Effect from "effect/Effect";
3 import { HttpServerRequest } from "effect/http/HttpServerRequest";
4 import * as HttpServerResponse from "effect/http/HttpServerResponse";
5 import { API_PORT, Marker, SECRET_NAME, Site } from "./shared.ts";
6
7 /**
8 * HTTP Service: reads the App secret via {@link Fly.GetSecret} and
9 * serves it back by name (never the plaintext).
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 secret = yield* Marker;
22 const get = yield* Fly.GetSecret(secret);
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 === "/secret") {
29 const got = yield* get().pipe(Effect.orDie);
30 return yield* HttpServerResponse.json({
31 ok: true,
32 name: got.name,
33 });
34 }
35 return yield* HttpServerResponse.json({
36 ok: true,
37 name: SECRET_NAME,
38 });
39 }),
40 };
41 }).pipe(Effect.provide(Fly.GetSecretHttp)),
42 ) {}