Is there a way to bind a key combo to send a piece of code to the REPL? I am developing a pedestal web service and it’s becoming a bit tiresome to navigate to the Rich comment block where my (restart-server)
call is every time I make some changes… :S
@simongray interceptors
is the service-map
in your start
The important line that you need in your service map while developing, would be (assoc ::http/routes route-fn)
.
That route-fn
dynamically expands the routes on every call - so point it to your routes
Ah, I see. So #'tech.matterindustries.titan.ion.api-gateway.service-handler/routes
is just a regular var that you’re deref’ing?
Yes, the app routing table
Ok. Thanks! I think I'm just not familiar with the syntax here. Never deref'ed a var before. Anyway, I guess it wouldn't work without the deref since yo made it this way. I'm just not sure why.
Yep: https://cursive-ide.com/userguide/repl.html#repl-commands
Awesomesauce!
Thank you very much! Works perfect.
@simongray it should not be necessary to call (restart-server)
in pedestal. This is our dev-server:
(defn- route-fn
"Use the deref of the namespace to get hot-reloaded namespaces."
[]
(route/expand-routes
(deref #'tech.matterindustries.titan.ion.api-gateway.service-handler/routes)))
(def interceptors
(-> service-handler/service
; Get ion provider out of there
(dissoc ::http/chain-provider)
; hot-reloaded-fn ftw!
(assoc ::http/routes route-fn)
(merge
{::http/type :jetty
::http/port 7001
::http/join? false})
(http/default-interceptors)
(http/dev-interceptors)))
Now everytime the route is hit, whatever code that was eval’ed in the REPL will get executed
I don’t know if this would be a cursive feature or nrepl feature, but how could I specify a snippet of code I want to run every time I reload a namespace while connected to REPL?
@danie Interesting. Can you explain a little how it works? I am currently working with something like
(defn start []
(http/start (http/create-server service-map)))
but I don’t see any servers started in your snippet so I’m unsure what to do with it…?Set an environment variable / system property when starting REPL, have top-level expression wrapped in (if my-env-var-is-set...)?