This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-20
Channels
- # adventofcode (7)
- # announcements (1)
- # aws (1)
- # babashka (127)
- # bangalore-clj (1)
- # beginners (54)
- # calva (8)
- # cider (12)
- # clj-http (2)
- # clj-kondo (8)
- # cljdoc (10)
- # cljs-dev (2)
- # clojure (48)
- # clojure-australia (14)
- # clojure-dev (6)
- # clojure-europe (105)
- # clojure-nl (6)
- # clojure-taiwan (1)
- # clojure-uk (62)
- # clojurebridge (1)
- # clojurescript (112)
- # code-reviews (4)
- # cursive (20)
- # data-science (1)
- # depstar (1)
- # events (8)
- # fulcro (6)
- # graalvm (11)
- # honeysql (2)
- # introduce-yourself (3)
- # jobs (1)
- # jobs-discuss (30)
- # malli (23)
- # nrepl (4)
- # off-topic (47)
- # pedestal (22)
- # polylith (10)
- # portal (3)
- # re-frame (16)
- # reitit (9)
- # releases (3)
- # rewrite-clj (1)
- # ring (1)
- # spacemacs (1)
- # tools-deps (12)
- # xtdb (7)
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))
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?(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
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 workbut 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})