Skip to content

Fastify middleware doesn't apply correctly when matched against routes registered via a Fastify plugin. #11802

Closed

Description

@DennisSnijder

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I'm currently working on a NestJS module which registers a UI and some endpoints via a Fastify plugin using a prefix.

 this.adapterHost.httpAdapter
        .getInstance()
        .register(this.registerPlugin(), {prefix: '/my-prefix'});

When registering a middleware for the routes matching the prefix, the middleware won't trigger.

configure(consumer: MiddlewareConsumer): any {
    consumer
      .apply(MyMiddleware)
      .forRoutes('/my-prefix', 'my-prefix', '/my-prefix/*')
 }

Minimum reproduction code

https://github.com/DennisSnijder/nestjs-bull-board-example

Steps to reproduce

  1. yarn install
  2. docker-compose up -d
  3. yarn start:dev
  4. visit: http://localhost:3000/queues

Expected behavior

When the configured routes for the endpoint is being reached, it should trigger the middleware provided.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.0.0

Packages versions

[System Information]
OS Version : macOS Unknown
NodeJS Version : v16.20.0
YARN Version : 1.22.19

[Nest CLI]
Nest CLI Version : 10.0.1

[Nest Platform Information]
platform-express version : 10.0.0
platform-fastify version : 10.0.0
schematics version : 10.0.1
testing version : 10.0.0
bullmq version : 1.1.0
common version : 10.0.0
core version : 10.0.0
cli version : 10.0.1

Node.js version

16.20

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

In the AppModule the middleware is being registered with the desired routes (in this example /queues).
The Fastify plugin is registered through the "BullBoardModule" see: https://github.com/felixmosh/bull-board/blob/master/packages/nestjs/src/bull-board.root-module.ts#L30

Interesting thing to notice: when reaching to an not existing url, the middleware does register (I guess it falls back to the NestJS route handler?) for example https://localhost:3000/queues/non-exisiting-route

Activity

  1. DennisSnijder commented on Jun 15, 2023

    @DennisSnijder
    Author

    Might be related to #11572 ?

  2. mareksuscak commented on Feb 19, 2024

    @mareksuscak

    @kamilmysliwiec is there any official recommendation as to how to get middleware to run before the routes registered with a plugin?

  3. freebeego commented on Jun 7, 2024

    @freebeego

    ?

  4. rafakwolf commented on Nov 30, 2024

    @rafakwolf

    Same problem here

  5. Hardanish-Singh commented on Jan 8, 2026

    @Hardanish-Singh

    Same issue

  6. added a commit that references this issue on Apr 29, 2026
    0894ee4
  7. kamilmysliwiec commented on Jul 23, 2026

    @kamilmysliwiec
    Member

    let's track this here #17350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions