@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 37 lines 1.24 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 Orders from "./orders.ts";
6 import Users from "./users.ts";
7
8 /**
9 * The only public Service. It joins the same network as {@link Users} and
10 * {@link Orders}, binds both, and serves `/users` and `/orders`.
11 */
12 export default class Gateway extends Fly.Service<Gateway>()(
13 "Gateway",
14 Effect.gen(function* () {
15 return {
16 main: import.meta.url,
17 network: yield* Fly.stackNetwork,
18 };
19 }),
20 Effect.gen(function* () {
21 const users = yield* Fly.bindService(Users);
22 const orders = yield* Fly.bindService(Orders);
23 return {
24 fetch: Effect.gen(function* () {
25 const request = yield* HttpServerRequest;
26 const path = new URL(request.url, "http://gateway").pathname;
27 if (path === "/users") {
28 return yield* HttpServerResponse.json(yield* users.list());
29 }
30 if (path === "/orders") {
31 return yield* HttpServerResponse.json(yield* orders.list());
32 }
33 return HttpServerResponse.text("try /users or /orders");
34 }).pipe(Effect.orDie),
35 };
36 }),
37 ) {}