Extracting a web handler from an `HttpApiBuilder` API for use in Cloudflare involves creating a f...

Hello, how can I get a web handler from a HttpApiBuilder api? (for use in cloudflare)

import { DefaultServices, Effect, Layer, ManagedRuntime } from "effect";
import { NodeContext, NodeHttpPlatform, NodeRuntime } from "@effect/platform-node";

import {
  FetchHttpClient,
  HttpApi,
  HttpApiBuilder,
  HttpApiEndpoint,
  HttpApiGroup,
  HttpApiSwagger,
  HttpApp,
  HttpMiddleware,
  HttpPlatform,
  HttpServer,
} from "@effect/platform";

const index = HttpApiGroup.make("index").add(HttpApiEndpoint.get("index", "/"));

export const Api = HttpApi.empty.add(index);

const IndexGroupLive = HttpApiBuilder.group(Api, "index", (handlers) =>
  Effect.gen(function* () {
    return handlers.handle("index", (req) => Effect.succeed("Hello World"));
  })
);

const ApiLive = Layer.provide(HttpApiBuilder.api(Api), IndexGroupLive);

const serve = HttpApiBuilder.serve(HttpMiddleware.logger).pipe(
  Layer.provide(HttpApiSwagger.layer()),
  Layer.provide(ApiLive),
)
Was this page helpful?