1import * as Cloudflare from "@/Cloudflare";
2import * as Effect from "effect/Effect";
3import * as HttpClientRequest from "effect/http/HttpClientRequest";
4
5/**
6 * Local-dev twin of `object.ts` with its own logical ids so
7 * `LocalContainer.test.ts` never shares a container application, Durable
8 * Object namespace, or worker with the live `Container.test.ts` deployment
9 * when the two files run concurrently.
10 */
11export class LocalRemoteContainer extends Cloudflare.Container<LocalRemoteContainer>()(
12 "LocalRemoteContainer",
13 {
14 image: "mendhak/http-https-echo:latest",
15 observability: { logs: { enabled: true } },
16 },
17) {}
18
19/**
20 * Durable Object that binds and starts the {@link LocalRemoteContainer} and
21 * proxies an HTTP request to the echo server running on port 8080 inside it.
22 */
23export class LocalRemoteContainerObject extends Cloudflare.DurableObject<LocalRemoteContainerObject>()(
24 "LocalRemoteContainerObject",
25 Effect.gen(function* () {
26 const container = yield* LocalRemoteContainer;
27
28 return Effect.gen(function* () {
29 const { fetch } = yield* container.getTcpPort(8080);
30
31 return {
32 hello: () =>
33 Effect.gen(function* () {
34 const response = yield* fetch(
35 HttpClientRequest.get("http://container/"),
36 );
37 return yield* response.text;
38 }),
39 };
40 });
41 }).pipe(
42 Effect.provide(
43 Cloudflare.Containers.layer(LocalRemoteContainer, {
44 enableInternet: true,
45 }),
46 ),
47 ),
48) {}