| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 4 | |
| 5 | /** |
| 6 | * Effect-native Worker fixture for the `Worker.URL` binding: yielding it |
| 7 | * attaches the binding and returns a deferred accessor; the handler reads |
| 8 | * the URL string and echoes it back. |
| 9 | */ |
| 10 | export default class UrlEffectWorker extends Cloudflare.Worker<UrlEffectWorker>()( |
| 11 | "UrlEffectWorker", |
| 12 | { |
| 13 | main: import.meta.url, |
| 14 | }, |
| 15 | Effect.gen(function* () { |
| 16 | const url = yield* Cloudflare.Worker.URL; |
| 17 | return { |
| 18 | fetch: Effect.gen(function* () { |
| 19 | const publicUrl = yield* url; |
| 20 | return yield* HttpServerResponse.json({ url: publicUrl }); |
| 21 | }), |
| 22 | }; |
| 23 | }), |
| 24 | ) {} |