-
Notifications
You must be signed in to change notification settings - Fork 100
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
Added @withMiddleware decorator for controllers and handlers #337
Conversation
This is pretty sweet. Any chance this will get merged to the project? |
Hi @priyath , @Minibrams, we are focused now on getting the main project green, it looks great! I'll have a look as soon as I can |
@notaphplover Let me know if I can be helpful in getting this merged or getting the project green 🙂 |
@Minibrams as soon as I merge this #344 Thanks for doing this. |
@Minibrams Will you please update this PR and resolve the conflicts? Thank you |
@dcavanagh Tried my best to resolve the conflicts. In the future I think it would be wise to postpone massive code-changes like those introduced by a linter until all/most other functional PRs have been merged. Linter changes will always cause a massive amount of merge conflicts that can be difficult to resolve, and it's very easy to overlook code being lost in the process. All of the currently open PRs are blocked by this. |
Rebased with changes from @rev42, tests now pass again - thank you! @dcavanagh Ready to merge now? |
@Minibrams hello, I went ahead and merged main and added some other things I wanted to change into main. |
@PodaruDragos thank you for the merge. |
Hello @PodaruDragos, can you please publish a new version including this feature to npm, it would be a very nice feature 🙏 |
hey @abarghoud i do not have any permissions for releasing. |
Hello @dcavanagh and @Jameskmonger, |
The pull request adds a
@withMiddleware()
decorator for registering middleware on controllers and handlers.Description
The
@withMiddleware()
piggybacks off of the existing way of registering controller- and handler middleware.The decorator takes a list of middleware and stores these as metadata that will be loaded when the corresponding
@controller()
orhttp...()
decorator is invoked. The middleware must implement theinterfaces.Middleware
interface, and as such can be defined as a simple(req, res, next) => { }
function or the symbol/string identifier for a containerised service that implements theBaseMiddleware
interface.Related Issue
#288
Motivation and Context
The
@withMiddleware()
decorator provides a nice and clean way of decorating endpoints with middleware, slightly reminiscent of ASP.NET controllers:It also provides a quick way of registering one-off middleware functionality:
How Has This Been Tested?
Wrote unit tests to define the desired behaviour of the decorator (see
/test/features/decorator_middleware.test.ts
).Wrote a small test controller and used
curl
to see if the middleware was indeed invoked as expected.Types of changes
Checklist: