| 1 | import * as Fly from "@/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 { isolatedProject } from "../../IsolatedProject.ts"; |
| 6 | |
| 7 | /** |
| 8 | * The isolated consumer project this service is bundled from (see |
| 9 | * `test/IsolatedProject.ts`): `main` lives outside the repository, so the |
| 10 | * bundle `cwd` resolves none of alchemy's dependencies and the bun |
| 11 | * bootstrap's own imports must be anchored by the bundler. |
| 12 | */ |
| 13 | export const project = isolatedProject("fly-service", import.meta.filename); |
| 14 | |
| 15 | export const IsolatedSite = Fly.App("IsolatedProjectSite", { |
| 16 | enableSubdomains: true, |
| 17 | }); |
| 18 | |
| 19 | /** |
| 20 | * Minimal `Fly.Service` served from an isolated project. `/health` |
| 21 | * answering 200 proves the generated bootstrap booted on the Machine — with |
| 22 | * its imports left external bun dies at module load and the app never |
| 23 | * answers. |
| 24 | */ |
| 25 | export default class IsolatedProjectApi extends Fly.Service<IsolatedProjectApi>()( |
| 26 | "IsolatedProjectApi", |
| 27 | { |
| 28 | app: IsolatedSite, |
| 29 | main: project.main, |
| 30 | region: "iad", |
| 31 | port: 3000, |
| 32 | guest: { cpuKind: "shared", cpus: 1, memoryMb: 256 }, |
| 33 | }, |
| 34 | Effect.gen(function* () { |
| 35 | return { |
| 36 | fetch: Effect.gen(function* () { |
| 37 | const request = yield* HttpServerRequest; |
| 38 | const url = new URL(request.url, "http://service"); |
| 39 | if (url.pathname === "/health") { |
| 40 | return yield* HttpServerResponse.json({ ok: true }); |
| 41 | } |
| 42 | return HttpServerResponse.text("hello from isolated project"); |
| 43 | }), |
| 44 | }; |
| 45 | }), |
| 46 | ) {} |