| 1 | import * as Hetzner from "@/Hetzner"; |
| 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("hetzner-service", import.meta.filename); |
| 14 | |
| 15 | export const IsolatedBox = Hetzner.Server("IsolatedProjectBox", { |
| 16 | serverType: "cpx12", |
| 17 | image: "ubuntu-24.04", |
| 18 | location: "nbg1", |
| 19 | }); |
| 20 | |
| 21 | /** |
| 22 | * Minimal `Hetzner.Service` served from an isolated project. `/health` |
| 23 | * answering 200 proves the generated bootstrap booted under its systemd |
| 24 | * unit — with its imports left external bun dies at module load and the |
| 25 | * port never answers. |
| 26 | */ |
| 27 | export default class IsolatedProjectApi extends Hetzner.Service<IsolatedProjectApi>()( |
| 28 | "IsolatedProjectApi", |
| 29 | { |
| 30 | server: IsolatedBox, |
| 31 | main: project.main, |
| 32 | port: 3000, |
| 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 | ) {} |