question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware forRoutes path matching inconsistent for RequestMethod.ALL and other RequestMethods

See original GitHub issue

I’m submitting a…


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

Current behavior

Not sure if it is intended behaviour, but it seems that path matching works differently for RequestMethod.ALL and other methods eg. RequestMethod.POST.

Expected behavior

Path matching is same for any of RequestMethod.

Minimal reproduction of the problem with instructions

Example module with middleware:

export class GatewayModule implements NestModule {
    configure(consumer: MiddlewareConsumer) {
        consumer
            .apply(FilterMiddleware)
            .forRoutes(
                { path: '/v1/users', method: RequestMethod.ALL },
                { path: '/v2/users', method: RequestMethod.POST }
            );
    }
}

For method RequestMethod.ALL both urls will match and be handled by middleware: /v1/users - ok /v1/users/123 - ok

For method RequestMethod.{POST,PUT,DELETE,GET,...} only first variant is matched handled by middleware: /v1/users - ok /v1/users/123 - not matched

To get same behaviour for ALL and the other request method, wildcards has to be used for non ALL request methods (eg. /v2/users**). This is not a huge problem, but I see this inconsistency something that is worth fixing.

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

I would like to build http proxy where proxying can be done to different servers based on request method.

Eg. configuration of a proxy (example for brevity may not make sense, posting here just to express the idea)

[
  {
    "path": ["/v1/users"],
    "target": "http://localhost:3003",
    "method": "DELETE"
  },
  {
    "path": ["/v2/users"],
    "target": "http://localhost:3001",
    "method": "ALL"
  },
]

Environment


Nest version: 5.6.2

 
For Tooling issues:
- Node version: 10.15.3  
- Platform:  macOS 

Others:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jsdevtomcommented, Nov 14, 2019

Probably a stupid question buy I’ll ask it anyway: Why doesn’t @All/RequestMethod.ALL map to app.all() instead of app.use()?

0reactions
kamilmysliwieccommented, Jan 25, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Middleware | NestJS - A progressive Node.js framework
For instance, the asterisk is used as a wildcard, and will match any combination of characters: forRoutes({ path: 'ab*cd', method: RequestMethod.ALL });.
Read more >
Nestjs: middleware for all routes except /auth - Stack Overflow
I am started with nestjs recently and i want apply a middleware for all routes, except the auth route.
Read more >
Mastering Roda - GitLab
So let's output the remaining path and the matched path in different sections of the routing tree. class App < Roda route do...
Read more >
The Pyramid Web Application Development Framework
Request method matching is the very most basic thing you can do with a view predicate ... to the same route, but different...
Read more >
Flow Framework
It can and usually will happen that Flow is launched from the command line by a different user. All users who plan.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found