| 1 | import * as Fly from "@/Fly"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 5 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 6 | import SecureUsers from "./secure-users.ts"; |
| 7 | |
| 8 | /** Public Service on the stack network that proxies to {@link SecureUsers}. */ |
| 9 | export default class SecureGateway extends Fly.Service<SecureGateway>()( |
| 10 | "SecureGateway", |
| 11 | Effect.gen(function* () { |
| 12 | return { |
| 13 | main: import.meta.url, |
| 14 | region: "iad", |
| 15 | network: yield* Fly.stackNetwork, |
| 16 | guest: { cpuKind: "shared" as const, cpus: 1, memoryMb: 256 }, |
| 17 | }; |
| 18 | }), |
| 19 | Effect.gen(function* () { |
| 20 | const users = yield* Fly.bindService(SecureUsers); |
| 21 | return { |
| 22 | fetch: Effect.gen(function* () { |
| 23 | const response = yield* users.fetch(HttpClientRequest.get("/")); |
| 24 | return HttpServerResponse.text(yield* response.text); |
| 25 | }).pipe( |
| 26 | Effect.catchCause((cause) => |
| 27 | Effect.succeed( |
| 28 | HttpServerResponse.text(Cause.pretty(cause), { status: 502 }), |
| 29 | ), |
| 30 | ), |
| 31 | ), |
| 32 | }; |
| 33 | }), |
| 34 | ) {} |