-
Notifications
You must be signed in to change notification settings - Fork 255
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 proposal #104
base: master
Are you sure you want to change the base?
middleware proposal #104
Conversation
start(port) { | ||
// set middlewares | ||
this.setBeforeMiddlewares( this._options.beforeMiddlewares || [] ) | ||
this.app.use(bodyParser.json({ verify: this._verifyRequestSignature.bind(this) })); |
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.
This gives us an opportunity to make this optional (but defaulting to active) in case you are handling other kinds of non-bot http requests with this express instance.
I, for example, have had to patch this in my own multipage bot in the past.
So we could make _verifyRequestSignature
"public", add a boolean this.shouldVerifyRequest
or something, set that default to true
and also add it before setBeforeMiddlewares
so we can halt the request before hitting other middlewares so we don't waste cpu cycles.
Or do you have a reason for setting it after setBeforeMiddlewares
@JacobGadawski?
I like it. Simple and to the point. |
afterMiddlewares.forEach( middleware => { | ||
this.app.use( middleware ) | ||
}) | ||
} |
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.
These two methods are identical, you can just have a setMiddlewares()
method and you just call it before and after initializing the webhooks with different params.
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.
@JacobGadawski, this is looking good. Just a few things I'd like to see in this PR before merging:
- Consolidate the two new methods into a single one.
- Add tests (at least for the new method)
- Update the README file with instructions on how to use these new options.
Let me know if you have any questions. Thanks!
I think we should add two methods:
The bot needs the Here's an example: https://stackoverflow.com/a/21293587/376680 What do you think @Charca ? |
I like the idea of making the Also, what's the reason we want to allow setting middlewares both before and after initializing the webhook? |
After a discussion with a bootbot user in Slack, I believe that we shouldn't allow I cannot foresee a situation where you would not need
This is the gist of what I was trying to say above. With the naming being:
As far as after middleware goes, I have no opinion. I feel like it is a common feature in middleware libraries, but that's as far as my opinion and expertise go. |
Adding the middleware to only |
This is My proposition to add middlewares to app instance in BootBot class. I want to add Raven/Sentry to my application but there is no option to add middlewares.