I'm using routes like so in my Pedestal webapp:
(def routes
[[["/" ^:interceptors [(body-params/body-params)
middlewares/params
params/keyword-params
coerce-body content-neg-intc
session-interceptor
ensure-db-interceptor
datomic-conn-db-interceptor]
{:get `home-page}]
;; other routes
This works fine. But I have a number of routes with common interceptors, so I'm trying to factor them out like so:
(def default-interceptors
[(body-params/body-params)
middlewares/params
params/keyword-params
coerce-body
content-neg-intc
session-interceptor
ensure-db-interceptor
datomic-conn-db-interceptor])
(def routes
[[["/" ^:interceptors default-interceptors
{:get `home-page}]
;; other routes...
When I navigate to this route, I get an exception:
clojure.lang.ExceptionInfo: java.lang.AssertionError in Interceptor :io.pedestal.http.route/router - Assert failed: Cannot expand '[#Interceptor{:name :io.pedestal.http.body-params/body-params} #function[io.pedestal.http.ring-middlewares/params] #Interceptor{:name :io.pedestal.http.params/keyword-params} {:name :service/coerce-body, :leave #function[service/fn--26867]} #Interceptor{:name :io.pedestal.http.content-negotiation/negotiate-content} #Interceptor{:name :io.pedestal.http.ring-middlewares/session} #Interceptor{:name :service/ensure-db-interceptor} #Interceptor{:name :service/datomic-conn-db-interceptor}]' as a route. Expected a verb map or path string, but found a class clojure.lang.PersistentVector instead
I'm not sure what's going wrong here. What is the correct way to do what I'm trying to do?
i needed a type hint on the interceptors vector var
(def default-interceptors
^:interceptors [(body-params/body-params)
middlewares/params
params/keyword-params
coerce-body
content-neg-intc
session-interceptor
ensure-db-interceptor
datomic-conn-db-interceptor])