-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.clj
More file actions
135 lines (124 loc) · 5.45 KB
/
service.clj
File metadata and controls
135 lines (124 loc) · 5.45 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
(ns net.thegeez.snippetlist.service
(:require [io.pedestal.log :as log]
[io.pedestal.http :as http]
[io.pedestal.http.route.definition :refer [defroutes]]
[io.pedestal.interceptor :as interceptor]
[io.pedestal.http.ring-middlewares :as middlewares]
[net.thegeez.w3a.breadcrumb :as breadcrumb]
[net.thegeez.w3a.edn :as edn]
[net.thegeez.w3a.form :as form]
[net.thegeez.w3a.html :as html]
[net.thegeez.w3a.link :as link]
[net.thegeez.snippetlist.auth :as auth]
[net.thegeez.snippetlist.auth.view :as auth.view]
[net.thegeez.snippetlist.users :as users]
[net.thegeez.snippetlist.users.view :as users.view]
[net.thegeez.snippetlist.snippets :as snippets]
[net.thegeez.snippetlist.snippets.view :as snippets.view]))
(def home
(interceptor/interceptor
{:enter (fn [context]
(merge context
{:response
{:status 200
:headers {"Content-Type" "text/html"}
:body (str "Hello world, snippetlist<br/>"
"<a href=\"" (link/link context :users/index) "\">/users</a><br/>"
"<a href=\"" (link/link context :snippets/index) "\">/snippets</a><br/>"
"<a href=\"" (link/link context :auth/login) "\">/login</a><br/>"
"<a href=\"" (link/link context :home) "\">/</a>")}}))}))
(defroutes
routes
[[["/"
^:interceptors [auth/with-auth
(breadcrumb/add-breadcrumb "Home" :home)
(html/for-html 404 (constantly "Not found"))
(edn/for-edn (fn [context]
{:data (get-in context [:response :data])
:breadcrumbs (:breadcrumbs context)}))]
{:get [:home home]}
["/login"
{:get
[:auth/login
^:interceptors [(html/for-html 200 auth.view/html-render-login)]
auth/login]
:post [:auth/login-post
^:interceptors [(html/for-html 422 auth.view/html-render-login)
(form/parse-form :credentials auth/login-form)]
auth/login-post]}]
["/logout" {:post [:auth/logout auth/logout-post]}]
["/users"
^:interceptors [(breadcrumb/add-breadcrumb "Users" :users/index)]
{:get
[:users/index
^:interceptors [(html/for-html 200 users.view/html-render-index)]
users/index]}
["/:id"
{:get
[:users/show
^:interceptors [(breadcrumb/add-breadcrumb "User" :users/show {:id [:request :path-params :id]})
(html/for-html 200 users.view/html-render-show)
(link/coerce-path-params {:id :long})
users/with-user]
users/show]}]]
["/snippets"
^:interceptors [(breadcrumb/add-breadcrumb "Snippets" :snippets/index)]
{:get
[:snippets/index
^:interceptors [(html/for-html 200 snippets.view/html-render-index)]
snippets/index]
:post
[:snippets/create
^:interceptors [auth/require-authentication
(html/for-html 422 snippets.view/html-render-new)
(form/parse-form :snippet snippets/snippet-form)
snippets/with-empty-snippet]
snippets/create]}
["/new"
{:get
[:snippets/new
^:interceptors [auth/require-authentication
(breadcrumb/add-breadcrumb "New Snippet" :snippets/new)
(html/for-html 200 snippets.view/html-render-new)
snippets/with-empty-snippet]
snippets/new]}]
["/:id"
^:interceptors [(breadcrumb/add-breadcrumb "Snippet" :snippets/show {:id [:request :path-params :id]})
(link/coerce-path-params {:id :long})
snippets/with-snippet]
{:get
[:snippets/show
^:interceptors [(html/for-html 200 snippets.view/html-render-show)]
snippets/show]
:post
[:snippets/edit-post
^:interceptors [auth/require-authentication
auth/require-authorization
(html/for-html 422 snippets.view/html-render-edit)
(form/parse-form :snippet snippets/snippet-form)]
snippets/edit-post]
:delete
[:snippets/delete
^:interceptor [auth/require-authentication
auth/require-authorization]
snippets/delete]}
["/edit"
{:get
[:snippets/edit
^:interceptors [auth/require-authentication
auth/require-authorization
(breadcrumb/add-breadcrumb "Edit" :snippets/edit {:id [:request :path-params :id]})
(html/for-html 200 snippets.view/html-render-edit)]
snippets/edit]}]
]]]]])
(def bootstrap-webjars-resource-path "META-INF/resources/webjars/bootstrap/3.3.4")
(def jquery-webjars-resource-path "META-INF/resources/webjars/jquery/1.11.1")
(def service
{:env :prod
::http/router :linear-search
::http/routes routes
::http/resource-path "/public"
::http/default-interceptors [(middlewares/resource bootstrap-webjars-resource-path)
(middlewares/resource jquery-webjars-resource-path)]
::http/type :jetty
})