| 1 | import * as Cloudflare from "@/Cloudflare/index.ts"; |
| 2 | import * as Config from "effect/Config"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | |
| 6 | /** |
| 7 | * Reads a `Config` value in Init (#1831). Changing the value must redeploy the |
| 8 | * Worker even though no binding and no code changed. |
| 9 | */ |
| 10 | export default class InitConfigWorker extends Cloudflare.Worker<InitConfigWorker>()( |
| 11 | "InitConfigWorker", |
| 12 | { |
| 13 | main: import.meta.url, |
| 14 | }, |
| 15 | Effect.gen(function* () { |
| 16 | const mode = yield* Config.String("INIT_CONFIG_WORKER_MODE").pipe( |
| 17 | Config.withDefault("unset"), |
| 18 | ); |
| 19 | return { |
| 20 | fetch: Effect.succeed(HttpServerResponse.text(mode)), |
| 21 | }; |
| 22 | }), |
| 23 | ) {} |