Fork me on GitHub
#reitit
<
2022-10-23
>
dharrigan18:10:48

One of the things that has bugged me a bit, is that if I modify a handler and re-eval my buffer, reitit (ring?) doesn't pick up the change, unless I reload the namespaces. So, now I'm doing this:

dharrigan18:10:53

(defn foo
  [_]
  {:status 200 :body "Hello World!"})

(def routes
  [["/foo" {:get {:handler #'foo]])

dharrigan18:10:13

(defn foo
  [_]
  {:status 200 :body "Hello World!"})

(def routes
  [["/foo" {:get {:handler foo]])

dharrigan18:10:49

Now if I modify foo to return, say "Good Bye World", and eval the function, the changes are picked up immediately.

dharrigan18:10:02

I'm curious if others are doing something similar or different?

Ben Sless18:10:17

I put everything in functions, and the dev handler is wrapped such that a new handler is instantiated for each request

ikitommi18:10:15

I think there should a dev/eval mode, for better repl experience oob. Personally, using mostly integrant and reseting anyway after any change.

dharrigan18:10:54

Yes, I'm at the moment using donut system and doing (ds/reset) to reload all the namespaces in, 'although much easier if I just eval a form 🙂

Ben Sless18:10:28

You can just add it as a flag when creating the handler Something I started leaning towards with Component, the more components, the better

dharrigan19:10:28

This is little tricker than I expected. I'm trying to get this to work with a ring/ring-handler and a ring/router. So far I'm tried (ring/ring-handler #(ring/router routes .... and (ring/ring-handler (ring/router #'routes.... with no joy. Either an exception is thrown when hitting a route (since the function '#( isn't returning a router (protocol) or nothing happens if I re-eval a route handler

dharrigan19:10:05

Is there an example somewhere of using the dev method with a ring setup?

dharrigan20:10:52

Thank you one and all (shout out to @UK0810AQ2) got it all nicely working now.