-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(web-server): allow injection of custom middleware. #1619
feat(web-server): allow injection of custom middleware. #1619
Conversation
@shanear Thanks! Knowledge about var DartMiddlewareFactory = function(config) {
return function(request, response, next) {
};
};
module.exports = {
'middleware:Dart': ['type', DartMiddlewareFactory]
}; example karma.config.js ...
middleware: ["Dart"]
... P.S. I use name |
Interesting It seems from the docs that launchers and frameworks are plugins, and all plugins are npm modules. Is that correct? It would be nice to be able to add project specific middleware without having to create a separate npm module for it. Again this is helpful for working with less modern, enterprise-style api's. |
@shanear you can inline plugin: ...
plugins: ['karma-*', {'middleware:InlineMiddleware': inlineMiddlewareFactory}]
middliware: ['inlineMiddleware']
... |
@maksimr great, i'll give that a shot. |
@maksimr how does this look? |
@shanear Thanks! Looks good for me 👍 @zzo, @dignifiedquire what do you think about this feature? |
I think this is a nice addition, but please add some documentation with example and squash your commits into one. |
@dignifiedquire cool! These docs look ok? If so, i'll squash everything up. |
|
||
**Description:** List of names of additional middleware you want the karma server to use. | ||
|
||
You must have installed the middleware via a plugin/framework (either inline or via NPM). An example of custom inline middleware is shown below. Additional information can be found in [plugins]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to mention that this is express/connect middleware, and have a link to their docs on how to write one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be good to note that the middleware is used in the order they are included, as the order can matter if I remember correctly.
@dignifiedquire i agree with your notes. Updated. Let me know what you think. |
this looks very interesting - middleware authors need to ensure they call 'next' if they don't want to handle a request - def. an advanced feature. What are all of the parameters the factory function gets - more than just 'config'? The karma-dart factory function gets:
|
@zzo Yeah, it's def advanced, but opens up a lot of flexibility in how Karma can be used (IE: we're using it to test our app's integration with a not-very-modern enterprise API). Plus many people working with node seem to be familiar with how connect/express work. The parameters are provided from the DI system. |
got it thanks - yes I think this is a great feature and ideally the karma-dart (and maybe other plugins?) should be transitioned to to use this ideally :) |
@dignifiedquire I added a sentence about the ordering. shanear@8984164#diff-b671a3609847ca11870b94dac48fd028R288 |
8984164
to
2e963c3
Compare
Thanks a lot |
feat(web-server): allow injection of custom middleware.
awesome 🤘 thanks for all of y'alls help! |
Published as |
mary poppins? I just looked at it the other day and it's up and running from what I could tell |
@zzo no all good old fashioned hand work |
@zzo but all automated, just need to run |
Took a crack at a simple way of adding custom middleware.
Closes #1612