Fork me on GitHub

Hey, I saw some cool examples for things done with babashka http-server, For example: I want to try working with it, but I'm not sure how to set up the workflow. It seems that to update changes in guestbook.clj I need to restart the server, and to reflect changes in guestbook.cljs I have to refresh the page. I tried to load the file into nrepl but then it starts a server and won't recieve new input. I'm probably missing some basic concept about how all of this work. So: Is there a way to refresh the page on file change? Is there a way to reload the server on file change? Is there a way to do actual hot reload? Thanks!

Michaël Salihi09:08:43

Hi @ozfraier > I tried to load the file into nrepl but then it starts a server and won't recieve new input. The reason is that the @(promise) block the thread, so new evals are blocked. One solution is to commenting the last part (server block) using the discard reader #_ before evaluate the file in the REPL and then call core-http-server to manually start the server (or evaluate the form (srv/run-server home-routes {:port port})). After that you can evaluate your modified blocks as usual.

(defn core-http-server []
  (srv/run-server home-routes {:port port}))

#_ ; <-- Check the discard reader
(let [url (str ":" port "/")]
  (println "serving" url)
  (browse/browse-url url)


Thank you @admin055 it works 🙂

Michaël Salihi10:08:49

You're welcome @ozfraier. Another solution (my preferred) is to use environment variable to exclude the server block when running the nrepl server dev=true bb --nrepl-server , so in your code you can put a condition against this env. It's what I'm doing in this project:

Michaël Salihi10:08:16

This way, we avoid the risk to commit with the discard reader. 👍


neat! thanks


@ozfraier @admin055 another way to do this is to use the babashka.file property:

(when (= *file* (System/getProperty "babashka.file"))
  (let [url (str ":" port "/")]
    (println "serving" url)
    (browse/browse-url url)
Then you can eval the file without accidentally running the server

Michaël Salihi21:08:26

Brilliant! This is definitely the solution that I will use from now on. Thanks @U0510902N!

Bobby Towers21:08:02

For my latest attempt at the Exercism test runner I ditched everything and went with a babashka script. It will run whenever code is submitted on the new site, and its job is to just take a solution file and a test file and output a detailed report. I'm going about this very naively, but I ended up overriding the reporting methods in clojure.test to store their results in atoms and process their contents accordingly. The next case that I need to handle is what to do if either of the files contain invalid code. The error output is actually perfect, I just don't know the proper way of capturing this data while the script (or another?) is running so that it can be included in the report and displayed to the user. The script is here: Any help or feedback would be appreciated, thanks! babashka


The error reporting stuff isn't exposed at this point but I want to do this in the near future

Bobby Towers21:08:40

Maybe I could pick it apart first with rewrite-clj and only test the valid forms.