Fork me on GitHub
#pedestal
<
2021-08-30
>
Lukas09:08:10

Hello, I'm trying out pedestal and I wonder if there is a way to reload an interceptor after modification without restarting the server everytime?

lispers-anonymous22:08:36

When setting up your server, you provide a :io.pedestal.http/routes key in the server config map. It's value can be the routes or a function that returns the routes. For development time, using a function will enable you to reload your code without restarting. That function should access your routes through the var that holds them (or the var of a function that returns the routes, if that is how you set it up). If you pass the routes directly, then the next time your code changes the routes that pedestal is holding onto will be the previous version of them.

(def my-routes
  #{["/home" :get some-interceptors]
    ["/dog/:name" :get dog-interceptors]})

;; ... later

(io.pedestal.http/create-server
  {:io.pedestal.http/routes 
   (fn [] 
     (io.pedestal.http.route/expand-routes (deref #'my-routes)))
   ;;... the rest of the server config
  })
Something like that should work. The repl support in pedestal is not very well documented. Note that if you use are using emacs and cider, cider-ns-refresh can destroy your vars and re-create them. That will require you to restart your repl, so avoid that command if possible.

🙏 2
Lukas07:08:16

Thanks a lot! I figured I missed a pair of parentheses. I wrote

::server/routes (fn [] (deref #'service/routes)) 
instead of
::server/routes (fn [] ((deref #'service/routes)))

lispers-anonymous12:08:04

Glad you got it figured out. This a great trick whenever you are providing something to a long running process and you want the ability to change the thing your code is providing out from under the process. It's not just a pedestal thing.