This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-07-08
Channels
- # announcements (16)
- # beginners (22)
- # calva (3)
- # cider (17)
- # clojure (2)
- # clojure-berlin (1)
- # clojure-denmark (4)
- # clojure-dev (4)
- # clojure-europe (22)
- # clojure-madison (1)
- # clojure-nl (2)
- # clojure-norway (34)
- # clojure-sweden (3)
- # clojure-uk (3)
- # clojurescript (9)
- # datomic (7)
- # deps-new (1)
- # events (1)
- # fulcro (1)
- # hyperfiddle (10)
- # lsp (43)
- # missionary (1)
- # off-topic (27)
- # pedestal (10)
- # polylith (1)
- # reitit (4)
- # releases (1)
- # squint (18)
- # xtdb (8)
Hi all! I use a reit router instead of the one built into the pedestal. I wanted to know if there is some way to install a high-level interceptor, but so that it is closer to the handler than a specific interceptor? Is it possible?
["/api"
{:interceptors [(interceptor :top)]}
["/sync"
{:interceptors [(interceptor :sync)]
:get {:interceptors [(interceptor :get)]
:handler handler}}]
=> [{"enter":"top"},{"enter":"api"},{"enter":"sync"},{"enter":"get"},<-i need :top interceptor here!->, "handler",{"leave":"get"},{"leave":"sync"},{"leave":"api"},{"leave":"top"}]
Yes, you could do that, but I don’t think there is documentation how to do that:
1. you can annotate the interceptor with some custom metadata to mark “should be re-ordered to the end of the chain”, e.g. could be a key like :priority
, :order
, :should-be-applied-last
etc.
2. you can modify the interceptor chain at router creation time using :reitit.interceptor/transform
key -> you get the chain of interceptors (normal order) and you should return a new chain (with new order) - here you can use the meta-data to sort the chain
3. example or re-ordering here: https://github.com/metosin/reitit/blob/master/test/cljc/reitit/interceptor_test.cljc#L220-L248
4. example of plugging in chain transformer here: https://github.com/metosin/reitit/blob/master/examples/http-swagger/src/example/server.clj#L150
hope this helps
Thanks a lot for the answer, really help. Perhaps there is also a mechanism that allows to wrap the handler like the middleware does in a regular ring, but with a pedestal? For things https://github.com/BrunoBonacci/mulog/blob/master/doc/ring-tracking.md. Like common wrapper for all handlers.