Hey Folks, I am using the BentoML summarization e...
# ask-for-help
a
Hey Folks, I am using the BentoML summarization example from the quickstart guide and building on top of it. I need functionalities such as JWT authentication, request-response logging, etc. I am creating middleware for each. In the documentation, it shows that we can add middleware to the class, but it does not mention how to add it for a particular route. When doing this
Summarization.add_asgi_middleware(JWTAuthentication)
, it adds the JWT authentication to other endpoints as well, such as
/livez
and
/metrics
. I want to only add middleware for the
summarize
method route. Please help me achieve that.
c
In your middleware code, you can ignore certain paths
a
I have around 3 to 4 middlewares, and I currently add conditions in each middleware to filter routes based on the path. While this approach works, I am looking for a simpler way to configure middleware for a specific method or route. Is there a more straightforward method to achieve this in BentoML?
c
Not that I’m aware of, this is pretty standard asgi stuff. You can probably abstract your code structure a bit to make it easier to maintain but it’s out of scope for bentoml
a
Thanks, Chaoyu. I'll likely try to make the code structure more abstract to simplify it.