-
Notifications
You must be signed in to change notification settings - Fork 1
/
systems.clj
59 lines (56 loc) · 2.32 KB
/
systems.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(ns example.systems
(:require
[system.core :refer [defsystem]]
[com.stuartsierra.component :as component]
(system.components
[h2 :refer [new-h2-database DEFAULT-MEM-SPEC DEFAULT-DB-SPEC]]
[http-kit :refer [new-web-server]]
[endpoint :refer [new-endpoint]]
[middleware :refer [new-middleware]]
[handler :refer [new-handler]])
[example.handler :refer [authors-routes directors-routes]]
[example.db :refer [create-tables!]]
[example.middleware :refer [wrap-not-found]]
[ring.middleware.format :refer [wrap-restful-format]]
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]
[environ.core :refer [env]]))
(defn dev-system []
(component/system-map
:db (new-h2-database DEFAULT-MEM-SPEC create-tables!)
:authors (component/using
(new-endpoint authors-routes)
[:db])
:directors (component/using
(new-endpoint directors-routes)
[:db])
:middleware (new-middleware {:middleware [[wrap-not-found :not-found]
[wrap-restful-format]
[wrap-defaults :defaults]]
:defaults api-defaults
:not-found "<h2>The requested page does not exist.</h2>"} )
:handler (component/using
(new-handler)
[:authors :directors :middleware])
:http (component/using
(new-web-server (Integer. (env :http-port)))
[:handler])))
(defn prod-system []
(component/system-map
:db (new-h2-database DEFAULT-DB-SPEC)
:authors (component/using
(new-endpoint authors-routes)
[:db])
:directors (component/using
(new-endpoint directors-routes)
[:db])
:middleware (new-middleware {:middleware [[wrap-not-found :not-found]
[wrap-restful-format]
[wrap-defaults :defaults]]
:defaults api-defaults
:not-found "<h2>The requested page does not exist.</h2>"} )
:handler (component/using
(new-handler)
[:authors :directors :middleware])
:http (component/using
(new-web-server (Integer. (env :http-port)))
[:handler])))