Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns interface.boot
"This namespace is only used while developing
to start and stop an internal webserver."
(:use [ring.adapter.jetty :only [run-jetty]]
[ring.middleware.stacktrace :only [wrap-stacktrace]])
(:require [interface.routes :as routes])
(:gen-class))
(def ^:dynamic *port* 8081)
(defonce server (atom nil))
(defn stop
"Stops the web application."
[]
(if-not (nil? @server)
(do
(.stop @server)
(reset! server nil))))
(defn start
"Starts or restarts the web application.
From a REPL:
(require 'interface.boot)
(interface.boot/start)"
[]
(stop)
(let [handler (wrap-stacktrace #'routes/app-routes)
s (run-jetty handler {:port *port* :join? false})]
(reset! server s)))
(defn restart
"Restarts the web application."
[]
(start))
(defn -main
[]
(start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.