wrap-reload Not Reloading Files #72
The wrap-reload middleware will reload your Clojure source files, but you still need to reference your handler as a var. In your example, route/routes is resolved once when the main function is evaluated. You need to ensure that you're referencing the var so that the reference is resolved each time the handler is called. In other words:
(bishop/handler #'routes/routes)That should fix your problem.
Thanks for the tip! Unfortunately the var reader syntax would not work because routes/routes is something unique bishop/handler takes, but bishop/handler returns a ring function. So I attempted to do
(defn main
"Exposes the main function for bootstrapping the application."
[& args]
(let [port (Integer/parseInt (get (System/getenv) "PORT" "3000"))
base-handler #'(bishop/handler routes/routes)
handler (if (= env "DEV") (wrap-stacktrace (wrap-reload base-handler))
base-handler)]
(println handler)
(println (str "Webserver starting on port " port " with env " env))
(run-jetty handler {:port port})))Which gave me an error, which is obvious now :)
So I ended up with this solution.
(def base-handler
(bishop/handler routes/routes))
(defn main
"Exposes the main function for bootstrapping the application."
[& args]
(let [port (Integer/parseInt (get (System/getenv) "PORT" "3000"))
handler (if (= env "DEV") (wrap-stacktrace (wrap-reload base-handler))
base-handler)]
(println handler)
(println (str "Webserver starting on port " port " with env " env))
(run-jetty handler {:port port})))Which is not ideal but its what I've got. Thanks for your help! Really appreciate it!
Maybe I can patch bishop to return a var for handlers so it plays nicer with ring middleware.
I am wrapping my response handler with wrap-reload but when I change one of my route files it does not reload the code as a result of it. Not sure if this is an issue with ns-tracker or wrap-reload.
@weavejester This one might be an issue with ns-tracker and since you made that and this I figured I'd just tag you, let me know if this is in poor taste. :)
OS: OSX Lion 10.7.4
Command to start process using foreman: lein trampoline run -m gameapi.core
Example Code: