Fork me on GitHub
Kira McLean16: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: 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 McLean16:10:51

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


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 {})


I think the wrong key version is correct.

Kira McLean18:10:53

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

Kira McLean18:10:41

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


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 McLean18:10:57

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


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

Kira McLean19:10:03

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

Kira McLean19:10:29

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