Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMiddleware runs for every matching route #1628
Comments
|
We could add a validation/matching step that would exclude overlapping routes. I like it! |
|
This is an expressjs issue, routes RouterProxy will still receive 2 requests. If you do this, then you will have to change all the logic of routes. Without using expressjs middlware. example in expressjs var express = require('express');
var app = express();
app.use('/user/test', function (req, res, next) {
console.log('test method');
next();
});
app.use('/user/:id', function (req, res, next) {
console.log('id method');
next();
});
app.get('/user/:id', function (req, res, next) {
res.send('USER');
});
app.listen(3000)
|
|
I'm aware of the router behavior in express, but this problem is not particularly about this. |
|
Can you please tell me where it's at? Where do you want me to look? |
|
hi // as is
[
{
path: '/cats/test',
method: RequestMethod.GET,
},
{
path: '/cats/:id',
method: RequestMethod.GET,
},
]
/* to be, it is like when it use '/cats' at forRoutes*/
[
{
path: '/cats',
method: RequestMethod.ALL,
}
] |
Current behaviorUse same Expected behaviorI think it should run once,because the same |
|
@underfin you applied it twice, so it runs twice. |
|
I have a try for this issue
|
|
@underfin Do you have an update? I am happy to work on this. |
|
I pull a pr #3187.If you hava an better idea.Just do it. |
|
No worries, will find another :) |


Looks closely related to #779
I'm submitting a...
Current behavior
Middleware is being called for every endpoint a request route could potentially match.
Expected behavior
Middleware should only be run once.
Minimal reproduction of the problem with instructions
Using the latest cats sample with the middleware applied from AppModule.
Create "conflicting" routes for the problem to occur
After
curl http://localhost:3000/cats/testthe server outputs:So the middleware is being applied twice, also once for the
:idendpoint which is unrelated to the current request. The middleware should stop after the first match.Note that if I use
.forRoutes('/cats')(instead of the controller class), I get the expected behaviour.Environment