Add @Terminates() decorator to prevent fallthrough and automatic response handling #222
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 (passingreq
andres
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.