Comments (5)
Hi,
I just tested this and in my case both requests trigger someMiddlewareFuction. Which express and routing-controllers versions are you using?
from routing-controllers.
Ahh the plot thickens!
package.json contents
"express": "^4.18.3",
"routing-controllers": "^0.10.4",
"reflect-metadata": "^0.2.1",
package-lock.json contents
"node_modules/express": {
"version": "4.18.3",
...
},
"node_modules/routing-controllers": {
"version": "0.10.4",
...
},
"node_modules/reflect-metadata": {
"version": "0.2.1",
...
}
from routing-controllers.
Well, this is a bit frustrating. I'm able to reproduce your issue. The problem is that express actually executes both controllers if you call next()
in them. In routing-controllers
there was a "fix" for this by setting a param to prevent multiple executions. The reason why it works inconsistently is because of the order of the middlewares/routes registered.
The fixed version doesn't trigger the middleware because after executing it tries to execute the next matching route, the :path one, but because of the "guard" in routing controllers, it stops the flow completely. If you try to execute the :path one, it will not try to execute the fixed one, so there is no stop in the flow, it will go to your outside middleware.
from routing-controllers.
Hmm so if I'm understanding correctly routing-controllers
has some built-in mechanism to prevent multiple matching handlers being invoked. But this only stops the control-flow when any route EXCEPT the last one is invoked. Normally this wouldn't be an issue (because the last route doesn't have anything else after it when everything is configured to use routing-controllers
) but since I'm using both routing-controllers
with some of my own middleware the behaviour is coming to light. Is this roughly with what you're saying?
If so, does that mean if I add a controller function like the following (at the bottom), it would effectively treat the testA/testB endpoints consistently?
@Get('*')
async testC(@Req() req: Request, @Res() res: Response) {
console.log('i am a special catch-all route')
}
from routing-controllers.
It would treat them consistently but also incorrectly. The short circuit was probably never meant to work this way and it was assumed the middlewares would be registered in routing-controllers
instead.
from routing-controllers.
Related Issues (20)
- question: building the code looks for Koa, while I'm only using Express HOT 8
- fix: class-validator does not work on last version of RC HOT 10
- fix: <Injected Response object is undefined> HOT 1
- question: @Get path with literal and variable HOT 3
- feature: <how make sub folder controllers> how make sub folder controllers HOT 2
- fix: jsdoc for Put http method, it mentions POST http method
- fix: TypeDI do not inject service HOT 1
- Annotate return type of `createExpressServer` with more narrow type HOT 1
- `cors: true` causes "Cannot set headers after they are sent to the client" error HOT 3
- fix: Global middlewares are not used if route prefix doesn't start with a slash ("/")
- fix: TypeError this.targetType.toLowerCase is not a function HOT 3
- fix: import statements should not affect the route matching order
- Can we create multiple paths for the same controller function? HOT 7
- fix: CJS being imported instead of ESM when trying to load controllers from directory import HOT 4
- feature: Allow to use `app.use(createExpressRouter())` instead of `useExpressServer(app)` HOT 6
- feature: Dynamic route HOT 5
- feature: Introduce Generics to CurrentUserChecker for Enhanced Type Safety HOT 2
- fix: body in middleware is undefined. I have bodyParser HOT 3
- question: How to execute code after the response is sent to client
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routing-controllers.