This commit is contained in:
@@ -7,8 +7,15 @@
|
|||||||
[org.httpkit.server :as http]
|
[org.httpkit.server :as http]
|
||||||
[reitit.coercion]
|
[reitit.coercion]
|
||||||
[reitit.coercion.spec]
|
[reitit.coercion.spec]
|
||||||
|
[reitit.ring.coercion]
|
||||||
|
[reitit.core :as r]
|
||||||
[reitit.ring]
|
[reitit.ring]
|
||||||
[ring.util.response :as response]))
|
[reitit.ring.middleware.exception]
|
||||||
|
[ring.util.response :as response]
|
||||||
|
[spec-tools.spell]
|
||||||
|
[reitit.spec]
|
||||||
|
[reitit.dev.pretty]
|
||||||
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
|
|
||||||
;;; Routes
|
;;; Routes
|
||||||
@@ -29,7 +36,20 @@
|
|||||||
(response/content-type "text/html")))
|
(response/content-type "text/html")))
|
||||||
|
|
||||||
(defn node-by-slug [req]
|
(defn node-by-slug [req]
|
||||||
(hello req))
|
(-> (hiccup/html {}
|
||||||
|
[:html
|
||||||
|
[:head
|
||||||
|
[:title "node-by-slug"]
|
||||||
|
doerg-html/charset
|
||||||
|
doerg-html/viewport]
|
||||||
|
[:body
|
||||||
|
[:h1 "node by slug"]
|
||||||
|
[:pre
|
||||||
|
(with-out-str
|
||||||
|
(pprint (:parameters req)))]]])
|
||||||
|
str
|
||||||
|
response/response
|
||||||
|
(response/content-type "text/html")))
|
||||||
|
|
||||||
(defn node-by-id [req]
|
(defn node-by-id [req]
|
||||||
(hello req))
|
(hello req))
|
||||||
@@ -37,11 +57,22 @@
|
|||||||
(def router
|
(def router
|
||||||
(reitit.ring/router
|
(reitit.ring/router
|
||||||
#{["/" {:get hello}]
|
#{["/" {:get hello}]
|
||||||
["/n/:slug" {:get node-by-slug
|
["/n/:slug" {:get
|
||||||
#_#_#_#_:coercion reitit.coercion.spec/coercion
|
{:handler node-by-slug
|
||||||
:parameters {:path {:slug ::slug/slug}}}]
|
:parameters
|
||||||
|
{:path {:slug (st/spec {:spec ::slug/slug})}}}}]
|
||||||
["/id/:id" {:get node-by-id}]}
|
["/id/:id" {:get node-by-id}]}
|
||||||
#_{:compile reitit.coercion/compile-request-coercers}))
|
{:validate reitit.spec/validate
|
||||||
|
:exception reitit.dev.pretty/exception
|
||||||
|
:spec (s/merge :reitit.spec/default-data)
|
||||||
|
#_#_
|
||||||
|
:reitit.spec/wrap spec-tools.spell/closed
|
||||||
|
#_#_:compile reitit.coercion/compile-request-coercers
|
||||||
|
:data
|
||||||
|
{:coercion reitit.coercion.spec/coercion
|
||||||
|
:middleware [reitit.ring.middleware.exception/exception-middleware
|
||||||
|
reitit.ring.coercion/coerce-request-middleware
|
||||||
|
reitit.ring.coercion/coerce-response-middleware]}}))
|
||||||
|
|
||||||
(defn match-by-path-and-coerce! [path]
|
(defn match-by-path-and-coerce! [path]
|
||||||
(if-let [match (r/match-by-path router path)]
|
(if-let [match (r/match-by-path router path)]
|
||||||
|
|||||||
@@ -60,7 +60,6 @@
|
|||||||
"invalid slug")
|
"invalid slug")
|
||||||
(->Slug string))
|
(->Slug string))
|
||||||
|
|
||||||
(defn slug? [s]
|
(s/def ::slug
|
||||||
(some? (from-string s)))
|
(s/conformer #(or (some-> % from-string)
|
||||||
|
::s/invalid)))
|
||||||
(s/def ::slug slug?)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user