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

Impossible to attach middleware to endpoints #130

Open
woodlamp-tech-admin opened this issue Jan 14, 2019 · 5 comments
Open

Impossible to attach middleware to endpoints #130

woodlamp-tech-admin opened this issue Jan 14, 2019 · 5 comments

Comments

@woodlamp-tech-admin
Copy link

I must be insane, because I see example after example online of this being done, yet it doesn't work on my system.

I have this:

(component/system-map
  :site-middleware (new-middleware {:middleware site-middleware-config})
  :site-endpoint   (-> (new-endpoint site-routes)
                       (component/using [:site-middleware]))
  :handler         (-> (new-handler :router :bidi)
                       (component/using [:site-endpoint]))
  :http            (-> (new-web-server (:http-port config))
                       (component/using [:handler])))

The middleware isn't mounting. I can't figure out from the code how Handler does its magic, but example after example shows that this is how to do it.

What am I doing wrong?

@jennykwan
Copy link

Gah identity management on GitHub sucks. That's me above.

@danielsz
Copy link
Owner

danielsz commented Jan 14, 2019

Hi @alyssackwan
I'm noticing that the enclosing vector in the middleware map is missing. Try this:

:site-middleware (new-middleware {:middleware [site-middleware-config}})

I hope this helps.

@jennykwan
Copy link

The site-middleware-config var is already a vector of wrap- functions.

I decided to revert from bidi to Compojure in my usage of Chestnut and that helped. I didn't test, but it doesn't seem like the wrap-mw calls to the outputs of bidi's make-handler can actually compose the same way that Compojure routes and middleware compose. I'm probably wrong, but I'll point to this thread including a philosophical statement by the maintainer of bidi (juxt/bidi#160).

@danielsz
Copy link
Owner

Ah, I see. So it works with Compojure, but not with Bidi?

@jennykwan
Copy link

Yes. Again, I haven't tested, but I think bidi.ring/make-handler takes a bidi struct and returns a Ring handler function, and system's handler component does a double make-handler call - once for endpoint components with :middleware directly attached to them, and then again to compose all the separate endpoints into the final handler. I conjecture that the outer make-handler can't be passed a Ring handler function (from the inner make-handler calls), only a bidi struct directly, which it gets with endpoint components without :middleware. Not too hard to test, but I haven't had time.

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

No branches or pull requests

3 participants