repl.clj 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. (ns web-client.repl
  2. (:use web-client.handler
  3. ring.server.standalone
  4. [ring.middleware file-info file]))
  5. (defonce server (atom nil))
  6. (defn get-handler []
  7. ;; #'app expands to (var app) so that when we reload our code,
  8. ;; the server is forced to re-resolve the symbol in the var
  9. ;; rather than having its own copy. When the root binding
  10. ;; changes, the server picks it up without having to restart.
  11. (-> #'app
  12. ; Makes static assets in $PROJECT_DIR/resources/public/ available.
  13. (wrap-file "resources")
  14. ; Content-Type, Content-Length, and Last Modified headers for files in body
  15. (wrap-file-info)))
  16. (defn start-server
  17. "used for starting the server in development mode from REPL"
  18. [& [port]]
  19. (let [port (if port (Integer/parseInt port) 3000)]
  20. (reset! server
  21. (serve (get-handler)
  22. {:port port
  23. :auto-reload? true
  24. :join? false}))
  25. (println (str "You can view the site at http://localhost:" port))))
  26. (defn stop-server []
  27. (.stop @server)
  28. (reset! server nil))