beginners

Zak Venter 2025-11-24T14:20:08.695259Z

Re-evalling in my repl doesn't seem to update the server. I've started off with the code given here https://code.thheller.com/blog/shadow-cljs/2024/10/18/fullstack-cljs-workflow-with-shadow-cljs.html

(ns recur.server
  (:require [ring.adapter.jetty :as jetty]
            [ring.middleware.file :as ring-file]
            [ring.middleware.file-info :as ring-file-info]
            [compojure.core :as cc]))

(defn my-handler [req]
  {:status 200
   :headers {"content-type" "text/plain"}
   :body "hello world from my-handler"})

(cc/defroutes app-routes
  (cc/POST "/api/test" req
    (comment "this line wont run unless i restart the whole server")
    ;; (println (:body req))
    {:status 200
     :headers {"content-type" "text/plain"}
     :body "hello world response"}))

(def handler
  (-> #'app-routes
      (ring-file/wrap-file "public")
      (ring-file-info/wrap-file-info)))

(defn -main [& args]
  (jetty/run-jetty handler {:port 3000}))
See the line with the comment. I've tried re starting the server from the repl (by running (repl/go), re evaluating all the functions etc. But for the line to take effect in the case of a post request I need to end the whole server and start it all over again.

Zak Venter 2025-11-24T14:20:29.314489Z

If anyone wishes to see the code in full it is here: https://github.com/Zakkkk/recur

seancorfield 2025-11-24T15:17:34.140989Z

(jetty/run-jetty handler {:port 3000}) needs to be (jetty/run-jetty #'handler {:port 3000}) -- see https://clojure.org/guides/repl/enhancing_your_repl_workflow#writing-repl-friendly-programs

seancorfield 2025-11-24T15:19:38.472659Z

(you did it for #'app-routes but not for handler and you may need it for my-handler references depending on how you write them)

Zak Venter 2025-11-24T22:45:39.929349Z

I'm assuming you mean in -main? I don't use -main to start the server, I use repl/go in which case it starts with:

(jetty/run-jetty #'srv/handler
                 {:port 3000
                  :join? false})
the dev/repl.clj file is this:
(ns repl
  (:require
   [shadow.cljs.devtools.api :as shadow]
   [recur.server :as srv]
   [ring.adapter.jetty :as jetty]))

(defonce jetty-ref (atom nil))

(defn start
  {:shadow/requires-server true}
  []
  (shadow/watch :frontend)

  (reset! jetty-ref
          (jetty/run-jetty #'srv/handler
                           {:port 3000
                            :join? false}))
  ::started)

(defn stop []
  (when-some [jetty @jetty-ref]
    (reset! jetty-ref nil)
    (.stop jetty))
  ::stopped)

(defn go []
  (stop)
  (start))
thanks for the article as well, ill give it a read

seancorfield 2025-11-24T22:49:47.699489Z

Maybe a Compojure issue with inline code then, since it's all macros. If you switch to declaring routes that map to #'some-handler fns instead of inline code, that should solve that.

Zak Venter 2025-11-24T22:52:59.848719Z

so you mean like each route in defroutes should be pointing to a function (with #'), instead of being inlined?

seancorfield 2025-11-24T23:01:32.219869Z

That's what I would do, yes.

Zak Venter 2025-11-24T23:02:38.551889Z

I'll give it a go, thanks!