Comments (9)
because both your actions satisfy executed route.
when you access user/all
it satisfies for both /:id
and all
. How can id
know if your "all" isn't id?
You can solve it either by using another route for all, either to specify regexp to "id" what it can be, and what it can't. For example:
/users/:id(\\d+)"
if id can be only a number
from routing-controllers.
Now, I understand the design. thx
I previously use express not in the proper way.
It needs to execute middlewares in the both sides of route.
from routing-controllers.
I know both of them match the path, but when the first returned why the second still process.
here is my error print:
getOne
getAll
[2016-08-17 14:34:15.362] [ERROR] app.js - Promise没有拒绝处理函数: Promise {
<rejected> Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
at ServerResponse.header (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:719:10)
at ServerResponse.json (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:247:10)
at ExpressDriver.handleError (D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\driver\ExpressDriver.js:248:22)
at D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\RoutingControllerExecutor.js:110:67
at process._tickCallback (internal/process/next_tick.js:103:7) } 原因: Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
at ServerResponse.header (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:719:10)
at ServerResponse.json (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:247:10)
at ExpressDriver.handleError (D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\driver\ExpressDriver.js:248:22)
at D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\RoutingControllerExecutor.js:110:67
at process._tickCallback (internal/process/next_tick.js:103:7)
from routing-controllers.
Because there is no logic that prevents execution of the second action if first returned something. Not sure if it should be there.
In your case you should have proper defined routes
from routing-controllers.
In your framework
if (action.isJsonTyped) {
response.json(result);
}
else {
response.send(String(result));
}
options.next();
why call next()
after response.send()
? Doing so will cause error
from routing-controllers.
because there can be a middleware that should be called after route execution (for example middleware that logs number of seconds spent on loading). Without calling next() it will not execute such middlewares
from routing-controllers.
And there can be some middlewares just deal with errors like 404 NOT FOUND. Like this, the middleware is always do the error handle, although there is no error need to be handled
from routing-controllers.
didnt get what you mean. Error handlers works different way, for error middleware you call next(err) and thats is called only when error occur, not always like in this case
from routing-controllers.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from routing-controllers.
Related Issues (20)
- fix: global middlewares (re)registered each time useExpressServer is called HOT 3
- question: @Param not type casted HOT 21
- 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 9
- 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
- question: Routes with path parameters continue middleware chain (but those without, don't)? HOT 5
- feature: Dynamic route HOT 4
- feature: Introduce Generics to CurrentUserChecker for Enhanced Type Safety HOT 1
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.