@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 64 lines 2.07 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 * as Redacted from "effect/Redacted";
7
8 export const Site = Fly.App("Site");
9 export const CacheOne = Fly.Redis("CacheOne");
10 export const CacheTwo = Fly.Redis("CacheTwo");
11
12 export class BoundSecrets extends Fly.Service<BoundSecrets>()(
13 "BoundSecrets",
14 {
15 app: Site,
16 main: import.meta.url,
17 count: 2,
18 port: 3000,
19 deploy: { strategy: "bluegreen", healthTimeout: "60 seconds" },
20 shutdown: { timeout: "10 seconds" },
21 services: [
22 {
23 protocol: "tcp",
24 internalPort: 3000,
25 autostop: "off",
26 ports: [{ port: 80, handlers: ["http"] }],
27 checks: [
28 {
29 type: "http",
30 port: 3000,
31 path: "/ready",
32 interval: "2s",
33 timeout: "1s",
34 },
35 ],
36 },
37 ],
38 },
39 Effect.gen(function* () {
40 const token = yield* Config.Redacted("ACCEPTANCE_BOUND_SECRET");
41 const slot = yield* Config.String("ACCEPTANCE_CACHE");
42 const cache = yield* Fly.ReadWriteRedis(slot === "one" ? CacheOne : CacheTwo);
43 const version = Redacted.value(token).endsWith("-one") ? "one" : "two";
44 return {
45 fetch: Effect.gen(function* () {
46 const request = yield* HttpServerRequest;
47 if (request.url.startsWith("/ready")) {
48 yield* cache.ping().pipe(Effect.orDie);
49 return HttpServerResponse.text("ready");
50 }
51 if (request.url.startsWith("/seed")) {
52 yield* cache.set("bluegreen-marker", version).pipe(Effect.orDie);
53 }
54 const value = yield* cache.get("bluegreen-marker").pipe(Effect.orDie);
55 return yield* HttpServerResponse.json({
56 config: version,
57 redis: value === "one" ? "one" : value === "two" ? "two" : "empty",
58 });
59 }),
60 };
61 }).pipe(Effect.provide(Fly.ReadWriteRedisHttp)),
62 ) {}
63
64 export default BoundSecrets;