Nest: Middleware applied on all routes

Created on 18 Jun 2018  路  4Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


A middleware is applied to all routes under a controller even after stating specific route to be applied to.

Expected behavior


Only the specified path should be affected by the middleware.

Minimal reproduction of the problem with instructions


As in this example, all routes under the users controller will be blocked by the middleware instead of only the users/:userId route.


...
consumer.apply(AuthMiddleware).forRoutes(
            'users/:userId'
        );
...

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.2.0


For Tooling issues:
- Node version: v9.11.1  
- Platform:  Mac 

Others:

question 馃檶

All 4 comments

Not sure what's the issue here. Could you share a bit more context?

I was trying to apply the AuthMiddleware on my routes but was going to exclude some of the routes per controller on the app. Say for example i have a User and Admin controllers, while i'll protect all routes in Admin, the User Controller has several methods including SignIn and SignUp which is not supposed to be affected by the AuthMiddleware. On previous versions of Nest, i could state the exact paths i want to apply the middleware to. Now it applies to all paths under a controller.


...
consumer.apply(AuthMiddleware)
    .forRoutes(
        'users/:userId'
    );
...

That was supposed to be applied to only the "users/:userId" route, now i can't access all routes under "users"

Actually, it's a duplicate of #779

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MonsieurMan picture MonsieurMan  路  28Comments

weeco picture weeco  路  28Comments

BrunnerLivio picture BrunnerLivio  路  44Comments

fmeynard picture fmeynard  路  45Comments

raydirty picture raydirty  路  37Comments