Someone here once showed me some trick to have the routes (and their interceptor chains) update more dynamically in the REPL when the underlying code changes, but I forgot what it was. I think it was some combination of characters like ’# and perhaps a few more lines of supporting code. Anybody know what I may be thinking of? Currently, I have to restart the service every time I want to see updated interceptor chains.
(defn- route-fn
"Use the deref of the namespace to get hot-reloaded namespaces."
[]
(route/expand-routes
(deref #'your.ns/routes)))
(-> service-handler/service
; hot-reloaded-fn ftw!
(assoc ::http/routes route-fn))
I think that was it, @danie! Thanks.
One question though: My routes are generated inside a function taking a config map:
(defn routes
[conf]
(route/expand-routes
(set/union (example-routes conf)
(sp.routes/all conf))))
I’m not sure how to represent that. your.ns/routes
in your example is just a var representing a data structure, right?I think it’s the deref that’s tripping me up
What is your ::http/routes
? Because whatever that is, you can deref?
(defn service-map
[conf]
{::http/routes (routes conf)
::http/type :jetty
::http/port 8080})
And then in my start
I deref an atom containing the overall conf, pass that to the function creating the service map and pass the created service map to http/create-server
what does service-handler/service
do?
that’s just the service map?
{::http/routes ((deref #'routes) conf)}
That may work?
hmm, probably not.
Ended up doing this
(defn routes
[conf]
(route/expand-routes
(set/union ((deref #'example-routes) conf)
((deref #'sp.routes/all) conf))))
(defn service-map
[conf]
{::http/routes #(routes conf)
::http/type :jetty
::http/port 8080})
and it seems to work(reloading the config doesn’t need to be dynamic, just the code changes)
thanks for you help!
but this also seems to work, so I’m unsure what deref’ing gets me:
(defn routes
[conf]
(route/expand-routes
(set/union (example-routes conf)
(sp.routes/all conf))))
(defn service-map
[conf]
{::http/routes #(routes conf)
::http/type :jetty
::http/port 8080})
{::http/routes #((deref #'routes) conf)}
That’s what I would have suggested. The deref so that it gets the latest installed routes
in the ns, on every invocation. And if what you have works, it works!
Ok, gonna try that out
thanks a lot for taking the time
Can confirm that #((deref #'routes) conf)
works great! Vars continue to confuddle me 😛