Fork me on GitHub
#reitit
<
2022-05-20
>
codeasone17:05:37

I decided to go back to basics in order to gain a better understanding of reitit-pedestal , but I've got stuck at first base 😳 With the following minimal src/core.clj https://gist.github.com/codeasone/950b5cd936ed0fffc4ab02d53afcd0d4, and having jacked-in to cider and evaluated (start), I was expecting to be able to modify/eval just the hello handler and reload http://localhost:8080/hello to see any changes I've made reflected, but no dice. Likewise, I can't just instrument hello in cider as I do usually and reload in the browser to start step debugging the handler. Would anyone be kind enough to point out what am I missing here? I've looked at the reitit example code which follows a similar pattern to my minimal example, and I've also dug a bit into the router-interceptor code, but I can't find a way to make things dynamic in the way I'd expect. Apologies in advance if this is blindingly obvious.

codeasone17:05:28

Hi @UG00LE5TN I did have a read through that document but none of the points raised seemed to help me resolve my particular issue. Maybe there's another way of establishing the routing interceptor which would allow me to benefit from the advice given: > calling a function rather than just passing router to the matching function... I read through the underlying code and couldn't figure out a way forward since the match-for-path invocation in the library code is taking a router and not doing anything smart like determining whether if was callable or not.

robertfw17:05:24

Hmm. Let me have a peek at the reitit-pedestal code

robertfw17:05:40

Caveat that this is just from looking at the code and having worked with interceptors some time ago, but the first approach I'd try is providing a development version of pedestal/routing-interceptor (which you'd continue using in prod). This dev-routing-interceptor would on :enter construct and enqueue a fresh pedestal/routing-interceptor , calling (routes) to get the latest version of your routes.

codeasone17:05:19

Something like this:

(defn routing-interceptor
  []
  (interceptor-helpers/before
   (fn [ctx]
     (chain/enqueue ctx [(pedestal/routing-interceptor (r/router (routes)))]))))

(defn start []
  (println "Server started")
  (reset! server
          (-> service-map
              http/default-interceptors
              (update ::http/interceptors #(conj % (routing-interceptor)))
              http/create-server
              http/start)))
works for my purposes, but I'm surprised this isn't supported in a more direct way by the library.

codeasone18:05:23

Just looking at the above gives me a headache, gives fresh meaning to the term "leaky abstraction" 😆 there must be an easier way...