duct

Kira McLean 2019-10-17T16:33:47.010200Z

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 McLean 2019-10-17T16:34:51.011100Z

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

teaforthecat 2019-10-17T17:15:45.011200Z

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

2019-10-17T18:24:30.011400Z

I think the wrong key version is correct.

Kira McLean 2019-10-17T18:33:53.011600Z

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

Kira McLean 2019-10-17T18:38:41.011800Z

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

teaforthecat 2019-10-17T18:41:27.012Z

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 McLean 2019-10-17T18:43:57.012200Z

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

2019-10-17T18:49:06.012400Z

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

Kira McLean 2019-10-17T19:31:03.012600Z

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

Kira McLean 2019-10-17T19:31:29.012800Z

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

👍 1