forked from Turee/clojurewebtutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.clj
More file actions
35 lines (32 loc) · 1.37 KB
/
Copy pathhandler.clj
File metadata and controls
35 lines (32 loc) · 1.37 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
(ns clojurewebtutorial.handler
(:require [compojure.api.core :as api]
[compojure.api.sweet :as sweet]
[ring.middleware.defaults :as defaults]
[clojurewebtutorial.features.pizza.handler :as pizza]
[clojurewebtutorial.graphql.handler :as graphql]
[cheshire.core]
[ring.middleware.json :as json-mw]
[ring.util.http-response :as hr]))
; This is example of a middleware
(defn example-middleware [handler]
(fn [req]
(println "Processing request" (:request-method req) (:uri req))
(time (handler req))))
(defn middleware [handler {:keys [ring-defaults]}]
(-> handler
(defaults/wrap-defaults ring-defaults) ;Sane default middleware
(json-mw/wrap-json-response) ;Converts clojure data to JSON and back
(example-middleware))) ;Just and example :)
(defn make-handler [context]
(-> (sweet/api
{:ui "/api-docs"
:spec "/swagger.json"}
(api/GET "/" [] ;Index route
(merge
(hr/resource-response "public/index.html")
{:headers {"Content-Type" "text/html"}}))
(api/context "/api/v1" []
(pizza/routes context))
(api/context "/graphql" []
(graphql/routes context)))
(middleware context)))