Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fastify Middleware is not Running #7569

Closed
j opened this issue Jul 14, 2021 · 11 comments
Closed

Fastify Middleware is not Running #7569

j opened this issue Jul 14, 2021 · 11 comments
Labels
needs triage This issue has not been looked into

Comments

@j
Copy link

j commented Jul 14, 2021

My authentication middleware is no longer working. I can't even register a simple middleware.

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): any {
    consumer
      .apply((req, res: any, next) => res.status(201).end('hi'))
      .forRoutes('(.*)') // I've tried "*", direct routes, { method: Post, path: "*" }, etc, etc...
  }
}

More context:

Reproduction: https://github.com/j/nestjs-middleware-bug

@j j added the needs triage This issue has not been looked into label Jul 14, 2021
@micalevisk
Copy link
Member

Please provide a minimium reproduction repository :)

@j
Copy link
Author

j commented Jul 15, 2021 via email

@micalevisk
Copy link
Member

micalevisk commented Jul 15, 2021

Maybe this could be related to #7511

@j
Copy link
Author

j commented Jul 15, 2021

@micalevisk I'll try to replicate this in another repo shortly.

@j
Copy link
Author

j commented Jul 15, 2021

@micalevisk https://github.com/j/nestjs-middleware-bug Here it is. Updated description. I can convirm it's the use of nestjs-mercurius. Without that it works. I didn't try @nestjs/graphql though.

@j
Copy link
Author

j commented Jul 15, 2021

I noticed that I have node_modules/fastify and node_modules/@nestjs/platform-fastify/node_modules/fastify when using mercurious. I never explicitly installed a second fastify. But it's concerning that my GraphQL server still works, etc, so I'm sort of confused.

@Zclhlmgqzc
Copy link
Contributor

Zclhlmgqzc commented Jul 15, 2021

I noticed that I have node_modules/fastify and node_modules/@nestjs/platform-fastify/node_modules/fastify when using mercurious. I never explicitly installed a second fastify. But it's concerning that my GraphQL server still works, etc, so I'm sort of confused.

use yarn rather than npm will fix it
nestjs-mercurius dep fastify-^3.19.1 but @nestjs/platform-fastify dep fastify-3.19.0

@kamilmysliwiec
Copy link
Member

Based on the conversation above, it seems that this issue isn't related to the framework. Basically, if you're installing the fastify package as a root dependency, always make sure to match the version that the @nestjs/platform-fastify uses internally.

@j
Copy link
Author

j commented Jul 15, 2021 via email

@j
Copy link
Author

j commented Jul 15, 2021 via email

@kamilmysliwiec
Copy link
Member

This has been discussed in the past and we decided to keep ws/socket.io/express/fastify as deps instead of peer deps of their corresponding "platform-*" packages because it's way safer (to better understand what's the reasoning here, check out PRs created by renovate when upgrading deps to see how many times we had to align adapters to libs + by looking at the issues tab you'll notice how frequently devs simply ignore peer deps restrictions and update one dependency without looking if it's compatible with another - see issues with @nestjs/swagger or rxjs after upgrading to v8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

4 participants