Skip to content
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

Question about route-middleware usage #394

Open
janosmeszaros opened this issue Oct 3, 2018 · 1 comment
Open

Question about route-middleware usage #394

janosmeszaros opened this issue Oct 3, 2018 · 1 comment

Comments

@janosmeszaros
Copy link

janosmeszaros commented Oct 3, 2018

Library Version(s)

[metosin/compojure-api "2.0.0-alpha25"]

Problem

Hi,

We've been using compojure-api for a while and it works great, although we just came across with an issue.
We have couple of endpoints defined with route-middleware where we are trying to use some middlewares like logging or a prometheus related one. This works just fine if the endpoint is defined with GET or POST macros but for some reason the endpoints defined with resource won't get wrapped with the middleware functions. As far as I could see this issue had been present in the previous version with middleware function too.
We worked around this problem defining middlewares in resource macros' :middleware param.

My question would be that, is there a way to solve this problem? Using route-middleware endpoints defined without GET, POST etc. macros?

Thanks
Janos

Here is an example endpoint which is having problem:

(context "test-endpoint" []
     (resource {:responses {200 {:schema domain/schema}}
                :get       {:parameters {:query-params domain/Request}
                               :handler    (handle-request)}}))
@ikitommi
Copy link
Member

ikitommi commented Oct 9, 2018

Great question.

route-middleware uses compojure.core/wrap-routes which is an elegant hack to applying middleware after route matching by using request injection. It requires the route to be wrapped into compojure.core/wrap-route-middleware to make it work. I think the resource doesn't do that. PR on that would be welcome.

PS. For simplicity on route & middleware definitions, there is also reitit, fixing all the issues inherited from Compojure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants