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"}]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.
I made it via transform, but maybe is better way
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