Difference Between Global Middleware in HttpRouter and HttpServer with Bun/Node Examples

whats the difference between setting a global middleware via HttpRouter.use, and via HttpServer.serve(HttpMiddleware.xxx)?

also for that matter, how do you even apply it on the platform-bun/node examples?

const AllRoutes = HttpRouter.Default.use((router) =>
  Effect.gen(function*() {
    yield* router.mount("/users", yield* UserRouter.router)
  })
).pipe(Layer.provide(AllUserRoutes))

const ServerLive = BunHttpServer.layer({ port: 3000 })

// use the `.unwrap` api to turn the underlying `HttpRouter` into another layer.
// Here we use `HttpServer.serve` to create a server from the `HttpRouter`.
const HttpLive = HttpRouter.Default.unwrap(HttpServer.serve(HttpMiddleware.logger)).pipe(
  HttpServer.withLogAddress,
  Layer.provide(AllRoutes),
  Layer.provide(ServerLive)
)
Was this page helpful?