mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Add an example project with integrant
This commit is contained in:
parent
bd5c67e75c
commit
c3e6682151
4 changed files with 71 additions and 0 deletions
11
examples/ring-integrant/.gitignore
vendored
Normal file
11
examples/ring-integrant/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/target
|
||||
/classes
|
||||
/checkouts
|
||||
pom.xml
|
||||
pom.xml.asc
|
||||
*.jar
|
||||
*.class
|
||||
/.lein-*
|
||||
/.nrepl-port
|
||||
.hgignore
|
||||
.hg/
|
||||
18
examples/ring-integrant/README.md
Normal file
18
examples/ring-integrant/README.md
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Ring Reitit example
|
||||
|
||||
A Sample project with ring and reitit.
|
||||
|
||||
## Usage
|
||||
|
||||
```clj
|
||||
> lein repl
|
||||
(start)
|
||||
```
|
||||
|
||||
Go with browser to:
|
||||
|
||||
* http://localhost:3000/ping
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2017-2018 Metosin Oy
|
||||
7
examples/ring-integrant/project.clj
Normal file
7
examples/ring-integrant/project.clj
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(defproject ring-integrant-example "0.1.0-SNAPSHOT"
|
||||
:description "Reitit Ring App with Swagger"
|
||||
: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})
|
||||
35
examples/ring-integrant/src/example/server.clj
Normal file
35
examples/ring-integrant/src/example/server.clj
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
(ns example.server
|
||||
(:require
|
||||
[reitit.ring :as ring]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[integrant.core :as ig]))
|
||||
|
||||
(defonce server (atom nil))
|
||||
|
||||
(def system-config
|
||||
{:example/jetty {:port 3000
|
||||
:join? false
|
||||
:handler (ig/ref :example/handler)}
|
||||
:example/handler {}})
|
||||
|
||||
(defmethod ig/init-key :example/jetty [_ {:keys [port join? handler]}]
|
||||
(println "server running in port" port)
|
||||
(jetty/run-jetty handler {:port port :join? join?}))
|
||||
|
||||
(defmethod ig/halt-key! :example/jetty [_ server]
|
||||
(.stop server))
|
||||
|
||||
(defmethod ig/init-key :example/handler [_ _]
|
||||
(ring/ring-handler
|
||||
(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))
|
||||
Loading…
Reference in a new issue