From c00c299e13a7088d6ecc73f9b04fb05ef628358f Mon Sep 17 00:00:00 2001 From: Daw-Ran Liou Date: Sun, 27 Oct 2019 11:02:49 -0700 Subject: [PATCH] Add integrant repl for better development experience - Create `user` ns for REPL-driven development. - Add entry point in `example.server` to start server in production. --- examples/ring-integrant/README.md | 14 +++++++++++--- examples/ring-integrant/dev/user.clj | 15 +++++++++++++++ examples/ring-integrant/project.clj | 7 +++++-- examples/ring-integrant/src/example/server.clj | 13 ++----------- 4 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 examples/ring-integrant/dev/user.clj diff --git a/examples/ring-integrant/README.md b/examples/ring-integrant/README.md index 0c3327cb..f0a522f5 100644 --- a/examples/ring-integrant/README.md +++ b/examples/ring-integrant/README.md @@ -4,9 +4,17 @@ A Sample project with ring and reitit. ## Usage -```clj -> lein repl -(start) +Run Ring server in command line: + +```bash +lein run +``` + +Run Ring server in the REPL + +```bash +lein repl +> (go) ``` Go with browser to: diff --git a/examples/ring-integrant/dev/user.clj b/examples/ring-integrant/dev/user.clj new file mode 100644 index 00000000..3db36b9a --- /dev/null +++ b/examples/ring-integrant/dev/user.clj @@ -0,0 +1,15 @@ +(ns user + (:require + [integrant.repl :as ig-repl] + [example.server])) + +(ig-repl/set-prep! (constantly example.server/system-config)) + +(def go ig-repl/go) +(def halt ig-repl/halt) +(def reset ig-repl/reset) + +(comment + (go) + (reset) + (halt)) diff --git a/examples/ring-integrant/project.clj b/examples/ring-integrant/project.clj index 367b299a..7db05f24 100644 --- a/examples/ring-integrant/project.clj +++ b/examples/ring-integrant/project.clj @@ -1,7 +1,10 @@ (defproject ring-integrant-example "0.1.0-SNAPSHOT" - :description "Reitit Ring App with Swagger" + :description "Reitit Ring App with Integrant" :dependencies [[org.clojure/clojure "1.10.1"] [ring/ring-jetty-adapter "1.7.1"] [metosin/reitit "0.3.10"] [integrant "0.7.0"]] - :repl-options {:init-ns example.server}) + :main example.server + :repl-options {:init-ns user} + :profiles {:dev {:dependencies [[integrant/repl "0.3.1"]] + :source-paths ["dev"]}}) diff --git a/examples/ring-integrant/src/example/server.clj b/examples/ring-integrant/src/example/server.clj index 5c9de4bb..04b82ca6 100644 --- a/examples/ring-integrant/src/example/server.clj +++ b/examples/ring-integrant/src/example/server.clj @@ -4,8 +4,6 @@ [ring.adapter.jetty :as jetty] [integrant.core :as ig])) -(defonce server (atom nil)) - (def system-config {:example/jetty {:port 3000 :join? false @@ -24,12 +22,5 @@ (ring/router ["/ping" {:get {:handler (fn [_] {:status 200 :body "pong!"})}}]))) -(defn start [] - (reset! server (ig/init system-config))) - -(defn stop [] - (swap! server ig/halt!)) - -(comment - (start) - (stop)) +(defn -main [] + (ig/init system-config))