This is where you will put all the code for "stateful" things like database connections and clients to external services.
src/example/system.clj
(ns example.system)
start-server
function in that namespace.
This should do what the example.main
namespace is
currently doing.
Just be sure to add a :join? false
to the set of
arguments. That way you can start the server and have it run in the
background.
(ns example.system
(:require [ring.adapter.jetty :as jetty]
[example.routes :as routes]))
(defn start-server
[]
(jetty/run-jetty #'routes/handler {:port 9999
:join? false}))
stop-server
function in that namespace.
This should take the server as its only argument and call
.stop
on it.
(ns example.system
(:require [ring.adapter.jetty :as jetty]
[example.routes :as routes])
(:import (org.eclipse.jetty.server Server)))
(defn start-server
[]
(jetty/run-jetty #'routes/handler {:port 9999
:join? false}))
(defn stop-server
[server]
(Server/.stop server))
start-system
function in that namespace.
This should return a map where the result of calling
start-server
is put under the ::server
key.
If you aren't familiar with the syntax, ::server
will
expand out to :example.system/server
(ns example.system
(:require [ring.adapter.jetty :as jetty]
[example.routes :as routes])
(:import (org.eclipse.jetty.server Server)))
(defn start-server
[]
(jetty/run-jetty #'routes/handler {:port 9999
:join? false}))
(defn stop-server
[server]
(Server/.stop server))
(defn start-system
[]
{::server (start-server)})
stop-system
function in that namespace.
This should call stop-server
on a server found under the
::server
key
(ns example.system
(:require [ring.adapter.jetty :as jetty]
[example.routes :as routes])
(:import (org.eclipse.jetty.server Server)))
(defn start-server
[]
(jetty/run-jetty #'routes/handler {:port 9999
:join? false}))
(defn stop-server
[server]
(Server/.stop server))
(defn start-system
[]
{::server (start-server)})
(defn stop-system
[system]
(stop-server (::server system)))
example.main
namespace to use
start-system
.
(ns example.main
(:require [ring.adapter.jetty :as jetty]
[example.system :as system]))
(defn -main []
(system/start-system))
just run
Nothing behavior-wise should be different.