| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 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 container 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 container |
| 11 | * bootstrap's own imports (`@effect/platform-bun`, `alchemy/*`, …) must be |
| 12 | * anchored by the bundler. |
| 13 | */ |
| 14 | export const project = isolatedProject( |
| 15 | "cloudflare-container", |
| 16 | import.meta.filename, |
| 17 | ); |
| 18 | |
| 19 | /** |
| 20 | * Minimal effectful `Cloudflare.Container` served from an isolated project. |
| 21 | * `ping` (RPC) and `/hello` (HTTP over the container's port 3000) answering |
| 22 | * prove the generated bootstrap booted — with its imports left external bun |
| 23 | * dies at module load and the Durable Object's requests never get a reply. |
| 24 | */ |
| 25 | export class IsolatedContainer extends Cloudflare.Container< |
| 26 | IsolatedContainer, |
| 27 | { ping: () => Effect.Effect<string> } |
| 28 | >()("IsolatedProjectContainer") {} |
| 29 | |
| 30 | export default IsolatedContainer.make( |
| 31 | { |
| 32 | main: project.main, |
| 33 | image: "oven/bun:latest", |
| 34 | }, |
| 35 | Effect.gen(function* () { |
| 36 | return { |
| 37 | ping: () => Effect.succeed("pong"), |
| 38 | fetch: Effect.gen(function* () { |
| 39 | const request = yield* HttpServerRequest; |
| 40 | const url = new URL(request.url, "http://container"); |
| 41 | if (url.pathname === "/health") { |
| 42 | return yield* HttpServerResponse.json({ ok: true }); |
| 43 | } |
| 44 | return HttpServerResponse.text("hello from isolated project"); |
| 45 | }), |
| 46 | }; |
| 47 | }), |
| 48 | ); |