This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-17
Channels
- # announcements (3)
- # babashka (3)
- # beginners (53)
- # biff (2)
- # calva (16)
- # cider (1)
- # clj-commons (1)
- # clj-kondo (97)
- # clj-on-windows (137)
- # clojure (49)
- # clojure-europe (63)
- # clojure-gamedev (1)
- # clojure-nl (2)
- # clojure-norway (50)
- # clojure-uk (4)
- # clojurescript (36)
- # core-async (28)
- # datomic (32)
- # emacs (22)
- # events (1)
- # graalvm (8)
- # honeysql (6)
- # jobs (2)
- # lambdaisland (5)
- # malli (6)
- # nbb (31)
- # off-topic (171)
- # pathom (14)
- # rdf (2)
- # reitit (4)
- # releases (2)
- # scittle (19)
- # shadow-cljs (46)
- # sql (6)
- # squint (6)
Hi! Thanks for creating Reitit. Is there a way to distinct
middlewares so that they don't get applied multiple times (in my case it's a side effecting middleware). A small example showing the issue is:
(let [middleware {:name :this-middleware-gets-executed-twice
:wrap identity}
router-options {:data {:middleware [middleware]}}
router (ring/router [["/one" {:handler identity
:middleware [middleware]}]]
router-options)
comp-routes (reitit.core/compiled-routes router)]
(clojure.pprint/pprint (-> comp-routes first second )))
Which outputs
{:middleware
[{:name :this-middleware-gets-executed-twice,
:wrap
#object[clojure.core$identity 0x746beac "clojure.core$identity@746beac"]}
{:name :this-middleware-gets-executed-twice,
:wrap
#object[clojure.core$identity 0x746beac "clojure.core$identity@746beac"]}],
:handler
#object[clojure.core$identity 0x746beac "clojure.core$identity@746beac"]}
This seems to happen in the route compilation process when the router is created. I guess it's the default append strategy used by meta-merge, but I'm not sure where I should inject logic to de-dup it.Hi! I’d first look into why the the middleware goes twice into the route-data in first place and see if there’s a simple way to just avoid doing it. If that doesn’t work out, it’s possible to manipulate the middleware chain https://cljdoc.org/d/metosin/reitit/0.5.18/doc/ring/transforming-middleware-chain
Thanks!