Skip to content
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

Add @Terminates() decorator to prevent fallthrough and automatic response handling #222

Closed
wants to merge 4 commits into from

Conversation

ArcanoxDragon
Copy link

Placing @Terminates() on an action prevents it from falling through to any future actions or middleware (except, of course, for error handling middleware in the event of an error). This is useful for routes which manually send reponse data or set headers, or for routes which call external handlers such as Browserify (passing req and res and letting the external handler provide content).

This decorator also prevents overlapping routes from conflicting. For example, if there are two actions defined, one for /js/bundle.js and one for /js/:file(*), under the master branch, both actions get called (see #220) which can cause issues with headers, etc. When @Terminates() is placed on /js/bundle.js, it no longer falls through to /js/:file(*) and properly terminates the route chain.

@ArcanoxDragon
Copy link
Author

I'm closing this in favor of explicit fallthrough instead of explicit termination. After more troubles with my app, it makes sense to require a decorator to fall through routes instead of assuming all routes should fall through. It's very uncommon for a route handler in Express to actually have a next parameter unless it is calling it for error handling purposes, which is already handled in routing-controllers. next shouldn't be called after an action handler runs unless the user opts in to it, in my opinion, simply because that's not how Express apps normally work.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant