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
Middleware #174
Comments
+1 for checking the need (or not) of asynchronous call, just a nuisance when augmenting the request. while we are at it, maybe could implement a |
I guess we could do something like: primus.before('middleware', reference, { priority: 1 }) But you could just specify them your self in the correct order. |
If we can guarantee that the order of execution will respect the order of insertion, i wouldn't add the |
I think that a priority based definition, as @pocesar mentioned, is an alternative to
Angular also supports a |
I think that's a good proposition @ruimarinho, since it would be backward compatible, since no older code uses the third parameter. but Primus would have to differentiate between what is a middleware and what's a plugin, or maybe there shouldn't be any difference at all, just the "priority queue" itself |
Landed in master. I decided not to implement priority as that would have complicated the a lot which is not worth it in my opinion. The middlewares are ran in order of insertion, so if you need a middleware layer to run before layer x it's up to the user to add it in the correct order. |
This issue discusses the middleware feature that will be added in the next iteration of Primus. We already have a plugin infrastructure in place which allows people to modify the Primus client and and server components but these plugins can not interact or intercept requests before they are passed in to the transformers themselves. By creating a middleware layer that is ran before we pass of the requests to the transformers we can build much more powerful and deeply integrated applications on top of primus.
As the plugins already make use of the
use
method which is frequently used by application frameworks that implement middleware support we have to pick a different name to add these kind of middleware layers. I want to suggest using the namebefore
for middleware as all this functionality is ran before anything else is executed. It would look something like this:The method will be chainable and force middleware layers to be named before they can be stored. The reason for this is that we want to be able to enable, disable and remove middleware layers as well.
This middleware layer also allows us to clean up some of the internals of Primus as we could transform the following functionality into a middleware layer:
/primus/primus.js
/primus/spec
As these will be implemented as middleware layers they could be disabled by developers or even overridden if the community comes up with a better way of doing these.
This would disable the middleware layer that is registered for the
spec
. The middleware eco system currently forces anext
param to the given function:This is a lot of pointless overhead for middleware that can be implemented synchronously. We can add a little
length
check on the given function to see the amount of params they accept and see if we need to process it async or sync.TL;DC/TL;DR
primus.before
for adding middlewareprimus.enable
for enabling a previously disabled middlewareprimus.disable
disable added middlewareprimus.remove
remove a middleware layer completely.The text was updated successfully, but these errors were encountered: