effect icon indicating copy to clipboard operation
effect copied to clipboard

RouteContext not available in HttpApiBuilder.middleware

Open sjanota opened this issue 1 month ago • 0 comments

What version of Effect is running?

3.19.3, platform 0.74.0, platform-node 0.70.0

What steps can reproduce the bug?

  1. Create a middleware with HttpApiBuilder.middleware that makes use of HttpRouter.RouterContext according to type definition this is fine.

    const middleware = HttpApiBuilder.middleware((app) =>
       Effect.gen(function* () {
         console.log('in the middleware);
         const ctx = yield* HttpRouter.RouteContext;
         console.log(
           `Context route for metrics middleware: ${ctx.route.method} ${ctx.route.path}`,
         );
    
         return yield* app;
       }),
    );
    
    
  2. Include the middleware in the app

     HttpApiBuilder.serve().pipe(Layer.provide(apiLayer), Layer.provide(middleware))
    
  3. Run and make any request

What is the expected behavior?

The middleware gets the context, logs it. The same middleware works perfectly fine with HttpRouter.

What do you see instead?

The servers fails with 500. Further debugging showed that yielding HttpRouter.RouteContext fails as the tag is not available in the context.

Additional information

No response

sjanota avatar Nov 14 '25 11:11 sjanota