-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client #491
Comments
your both route should not same . it should be like this @jsoncontroller()
} |
Well, I know I can do this way. But this doesn't solve the issue. It should not execute both handlers. Now it does a conflict between routes. |
id is a number so you can use regex to be stricter on the matching. @Get("/users/:id([0-9]+)") |
I have the same error. I use // catch 404 and forward to error handler
// app.use(function (req: Request, res: Response, next: NextFunction) {
// res.status(404);
// res.send({
// code: 404,
// message: "Not Found"
// });
//}); |
I had the same issue. This was my workaround in the end so that i could keep the custom 404 middleware: app.use(function (req: Request, res: Response, next: NextFunction) {
if (!res.finished) {
res.status(404).json(
{
status: 404,
message: `Cannot ${req.method} ${req.url}`,
}
);
}
res.end();
}); It basically checks if headers were already sent ond only if not sends the 404 infos. But I'm still curious about the PROPER way to do this. The official way of doing things is the one that @doghappy mentioned, see http://expressjs.com/en/starter/faq.html but it does not work, at least in the context with |
This has been fixed. |
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. |
Hi all.
When I have the following case, routing controllers fails and try to execute both functions:
As far as I read it should execute first occurency not both.
Thanks!
The text was updated successfully, but these errors were encountered: