Fork me on GitHub
#reitit
<
2022-02-04
>
jeroenvandijk12:02:56

Is there a way in (or with) reitit to compose middleware so that it is executed in the right order and not multiple times? I’m thinking of creating modules that would declare their middleware dependencies and then combine those modules ( potentially leading to duplicates and wrong ordering).

jeroenvandijk16:02:53

I didn’t find something, but rethinking this, maybe better to define middleware per endpoint and use the https://cljdoc.org/d/metosin/reitit/0.5.15/doc/ring/middleware-registry to reuse common middleware

jeroenvandijk15:02:03

I’ve worked out an example of composing middleware in a smarter way. Not sure if this is a new idea or not. I have used the idea of an (half-)interceptor plus the dependency code in reitit. Feels like an improvement to me. What do you think? https://gist.github.com/jeroenvandijk/85f57c168ef9a39cc9af7dfa360cee61

jeroenvandijk10:02:27

I found https://quanttype.net/posts/2018-08-03-why-interceptors.htmland it mentioned something https://github.com/oliyh/angel-interceptor/blob/master/src/angel/interceptor.clj, but this is mostly in the context of interceptors whereas I think it could also be applied to (adapted) ring middleware

wontheone116:02:04

Hi, I didn't find a channel for testit so here it goes because maintained by same people. https://github.com/metosin/testit/pull/31

ikitommi17:02:04

merged, thanks

👍 1
jeroenvandijk15:02:03

I’ve worked out an example of composing middleware in a smarter way. Not sure if this is a new idea or not. I have used the idea of an (half-)interceptor plus the dependency code in reitit. Feels like an improvement to me. What do you think? https://gist.github.com/jeroenvandijk/85f57c168ef9a39cc9af7dfa360cee61