mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
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.
This commit is contained in:
parent
c3e6682151
commit
c00c299e13
4 changed files with 33 additions and 16 deletions
|
|
@ -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:
|
||||
|
|
|
|||
15
examples/ring-integrant/dev/user.clj
Normal file
15
examples/ring-integrant/dev/user.clj
Normal file
|
|
@ -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))
|
||||
|
|
@ -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"]}})
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue