Fork me on GitHub
#duct
<
2019-10-17
>
Kira Howe16:10:47

Hi there.. I have a noob question about wiring up middleware in a duct app. Any chance this is the right place to ask? I want to wrap every request with this flash middleware: https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/flash.clj. I thought adding it like this would do (in my base config):

:duct.handler/root {:middleware [
                                  ;; other middlewares...
                                  #ig/ref :my.flash.middleware
                                  ]}
where :my.flash.middleware is just this:
(defmethod ig/init-key :my.flash.middleware/flash [_ _]
  #(rf/wrap-flash %))
.. but it doesn't work. Manually wrapping handlers with wrap-flash appears to work, but I'm struggling to get it wired up for every request.

Kira Howe16:10:51

I'm hoping there's just something simple misconfigured.

teaforthecat17:10:45

I remember something about the a namespace named middleware being treated specially, so this may not be the right answer. Have you tried referring to the whole key like #ig/ref :my.flash.middleware/flash ? (I believe that would also have to be a top level key like :my.flash.middleware/flash {})

jahson18:10:30

I think the wrong key version is correct.

Kira Howe18:10:53

Ah interesting. Thanks for the idea.. I'll give it a shot.

Kira Howe18:10:41

Hmm no luck.. I'm wondering if some other middleware is interfering, maybe clobbering the session or something.

teaforthecat18:10:27

you might be in println debugging territory. or can you set a breakpoint? If so you could make a defn just for the purpose of setting a breakpoint.

Kira Howe18:10:57

Hmm boo. Will head down that path. But yeah I should be able to run the site with breakpoints.

jahson18:10:06

You should also try to print the config, it should be availabe from the dev ns

Kira Howe19:10:03

the issue was that this ring flash middleware was already included in the defaults for our app :woman-facepalming:

Kira Howe19:10:29

So calling it twice caused problems. Very stupid oversight.. anyway, all set now.

👍 4