@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 40 lines 1.28 KB
Raw
1 import * as Fly from "@alchemy.run/fly";
2 import * as Config from "effect/Config";
3 import * as Effect from "effect/Effect";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6 import { API_PORT, Marker, SECRET_NAME, Site } from "./shared.ts";
7
8 /**
9 * HTTP Service: Fly injects {@link Marker} as env `{@link SECRET_NAME}`.
10 * Read it from `fetch` with `Config.String` — never the plaintext.
11 */
12 export default class Api extends Fly.Service<Api>()(
13 "Api",
14 {
15 app: Site,
16 main: import.meta.url,
17 region: "iad",
18 port: API_PORT,
19 guest: { cpuKind: "shared", cpus: 1, memoryMb: 256 },
20 },
21 Effect.gen(function* () {
22 yield* Marker;
23
24 return {
25 fetch: Effect.gen(function* () {
26 const request = yield* HttpServerRequest;
27 const url = new URL(request.url, "http://service");
28 const value = yield* Config.String(SECRET_NAME).pipe(Effect.orElseSucceed(() => ""));
29 const body = {
30 ok: value.length > 0,
31 name: SECRET_NAME,
32 };
33 if (url.pathname === "/health" || url.pathname === "/secret") {
34 return yield* HttpServerResponse.json(body);
35 }
36 return yield* HttpServerResponse.json(body);
37 }),
38 };
39 }),
40 ) {}