-
Notifications
You must be signed in to change notification settings - Fork 109
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
Inject custom Express request properties using @ContextRequestProperty decorator #105
base: master
Are you sure you want to change the base?
Inject custom Express request properties using @ContextRequestProperty decorator #105
Conversation
Codecov Report
@@ Coverage Diff @@
## master #105 +/- ##
==========================================
- Coverage 94.46% 94.41% -0.06%
==========================================
Files 14 14
Lines 1103 1110 +7
Branches 189 189
==========================================
+ Hits 1042 1048 +6
- Misses 61 62 +1
Continue to review full report at Codecov.
|
I don't get it. |
A common pattern in express is to attach custom data to the request prototype from inside a middleware function so that subsequent middlewares/route handlers may have access to it. For example, if you want to restrict access to a route only for authenticated users, you can use a middleware for this purpose, and you can also pass along the user id retrieved from the authentication procedure to the route handler method to save an additional db lookup. You could then access this value by injecting the req object into your route handler function and then retrieving the new property you attached. This PR makes it so that you can inject the custom property directly into your method, i.e. if you attach a value See: https://stackoverflow.com/questions/12518132/modifying-express-js-request-object https://stackoverflow.com/questions/37377731/extend-express-request-object-using-typescript |
Allows the following behavior: