Fork me on GitHub
Cristian Saucedo16:07:39

If I have middleware {:middleware [my-mw]} that is defined as a compiled middleware with options def my-mw {:name ::foo :compile (fn [{:keys [hello world]} options] ...) . How to I pass in the options map? I tried {:middleware [[my-mw options-map]]} but that does not compile, giving an arity warning. I tried adding a options key to routes where I want it used, but that didn't seem to work either


if i understand correctly, that vector form is converted into a canonical middleware representation, by (reitit.middleware/into-middleware [my-mw options-map] route-data router-opts), where router-opts can contain for example a reitit.middleware/registry which can map keywords to middlewares. try to see if calling that function directly with your example yields what u expect.


given a ring handler:

(defn test-handler [req] {:status 200, :headers {}, :body "hello"})
i create a ring router using the var of the handler:
(-> ["/" {:get {:handler #'test-handler}}] reitit.ring/router reitit.core/routes)

=> [["/" {:get {:handler #'xxx/test-handler}}]]
however, i get an error, if i try to create a "http" router from it:
(-> ["/" {:get {:handler #'test-handler}}] reitit.http/router)

Execution error (ExceptionInfo) at reitit.exception/exception (exception.cljc:19).
No implementation of method: :into-interceptor of protocol: #'reitit.interceptor/IntoInterceptor found for class: clojure.lang.Var
i was expecting the middleware and the interceptor based implementations compatible in this regard. i don't understand why does the middleware router even accepts vars. i don't see it explicitly supported:
  (-> reitit.interceptor/IntoInterceptor :impls keys set)
  (-> reitit.middleware/IntoMiddleware :impls keys set))