Effect CommunityEC
Effect Community8mo ago
11 replies
André König

How to Inject RpcGroup-wide Middleware with RpcServer.toWebHandler

Can anybody point me in the right direction on how to "inject" a RpcGroup-wide middleware when using RpcServer.toWebHandler? This is what I have so far, but I can't get the layer right. Any pointers are highly appreciated.

const layer = Layer.mergeAll(
  CreatorApiImpl,
  RpcSerialization.layerNdjson,
  HttpServer.layerContext,
)

export function toTanStackStartApiHandler({ request }: { request: Request }) {
  const { handler } = RpcServer.toWebHandler(CreatorApi, {
    layer,
  })

  return handler(request)
}
Was this page helpful?