reitit
reitit copied to clipboard
reitit.pedestal/replace-last-interceptor does not replace pedestal router
I'm not sure what the intent is for (replace-last-interceptor)
but it seems to aim to replace the built-in pedestal router with the reitit one instead.
However, it doesn't actually do that in the latest two versions of pedestal, because pedestal's routing interceptor is not at the end of the list:
(require '[io.pedestal.http :as http])
; => nil
(-> {:env :dev ::http/type :jetty ::http/port 8080 ::http/routes []}
(http/default-interceptors))
; =>
{:env :dev,
:io.pedestal.http/type :jetty,
:io.pedestal.http/port 8080,
:io.pedestal.http/routes [],
:io.pedestal.http/interceptors [#Interceptor{:name :io.pedestal.http/log-request}
#Interceptor{:name :io.pedestal.http/not-found}
#Interceptor{:name :io.pedestal.http.ring-middlewares/content-type-interceptor}
#Interceptor{:name :io.pedestal.http.route/query-params}
#Interceptor{:name :io.pedestal.http.route/method-param}
#Interceptor{:name :io.pedestal.http.secure-headers/secure-headers}
#Interceptor{:name :io.pedestal.http.route/router}
#Interceptor{:name :io.pedestal.http.route/path-params-decoder}]}
;;;;
(-> {:env :dev ::http/type :jetty ::http/port 8080 ::http/routes []}
(http/default-interceptors)
(pedestal/replace-last-interceptor (pedestal/routing-interceptor [])))
{:env :dev,
:io.pedestal.http/type :jetty,
:io.pedestal.http/port 8080,
:io.pedestal.http/routes [],
:io.pedestal.http/interceptors [#Interceptor{:name :io.pedestal.http/log-request}
#Interceptor{:name :io.pedestal.http/not-found}
#Interceptor{:name :io.pedestal.http.ring-middlewares/content-type-interceptor}
#Interceptor{:name :io.pedestal.http.route/query-params}
#Interceptor{:name :io.pedestal.http.route/method-param}
#Interceptor{:name :io.pedestal.http.secure-headers/secure-headers}
#Interceptor{:name :io.pedestal.http.route/router}
#Interceptor{:name :reitit.http/router}]}
The (replace-last-interceptor)
call replaces the ::http/path-params-decoder
interceptor instead.
(You can see the code which generates these here.)
Is there a better way to replace the pedestal router? Should I instead just leave the interceptor alone, add the reitit.pedestal/routing-interceptor
to the end of my list of interceptors, and set the pedestal ::http/routes
to []
?