Using `HttpApiBuilder.toWebHandler` with Next.js

How do I use
HttpApiBuilder.toWebHandler
? I currently have followed the README.md instructions for creating an API, and everything works fine, but now I want to create a Web request handler that I can forward to Next.js. This is my code currently:


const HttpLive = HttpApiBuilder.serve(HttpMiddleware.logger).pipe(
  // Add CORS middleware
  Layer.provide(HttpApiBuilder.middlewareCors()),
  // Provide the API implementation
  Layer.provide(apiLive),
  // Log the address the server is listening on
  HttpServer.withLogAddress,
  // Provide the HTTP server implementation
  Layer.provide(NodeHttpServer.layer(createServer, { port: 3000 }))
)

HttpApiBuilder.toWebHandler(apiLive.pipe(
  Layer.provide(NodeHttpPlatform.layer),
))
/*
^^ Gives errors:
Argument of type 'Layer<Api, never, never>' is not assignable to parameter of type 'Layer<Api | DefaultServices, never, never>'.
  Type 'Api | DefaultServices' is not assignable to type 'Api'.
    Type 'HttpPlatform' is missing the following properties from type 'TagClassShape<"@effect/platform/HttpApi/Api", { readonly api: HttpApi<AnyWithProps, never, never>; readonly context: Context<never>; }>': Id, Type, [TagTypeId]ts(2345)

*/
Was this page helpful?