Skip to content

RouteContext not available in HttpApiBuilder.middleware #5747

@sjanota

Description

@sjanota

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions