1import * as Cloudflare from "@/Cloudflare";
2import * as Effect from "effect/Effect";
3import { HttpServerRequest } from "effect/http/HttpServerRequest";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5
6/**
7 * Effect-native worker used as the *callee* of the `Fetch` capability
8 * fixtures. Echoes the query-string `name` back so the caller can prove the
9 * request actually crossed the service binding.
10 */
11export default class FetchTargetWorker extends Cloudflare.Worker<FetchTargetWorker>()(
12 "FetchTargetWorker",
13 {
14 main: import.meta.url,
15 },
16 Effect.gen(function* () {
17 return {
18 fetch: Effect.gen(function* () {
19 const request = yield* HttpServerRequest;
20 const name =
21 new URL(request.url, "http://x").searchParams.get("name") ?? "world";
22 return HttpServerResponse.text(`fetch-binding-target: hello ${name}`);
23 }),
24 };
25 }),
26) {}