diff --git a/publisher/src/net/deertopia/publisher/server.clj b/publisher/src/net/deertopia/publisher/server.clj index 5a19777..01904f6 100644 --- a/publisher/src/net/deertopia/publisher/server.clj +++ b/publisher/src/net/deertopia/publisher/server.clj @@ -7,8 +7,15 @@ [org.httpkit.server :as http] [reitit.coercion] [reitit.coercion.spec] + [reitit.ring.coercion] + [reitit.core :as r] [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 @@ -29,7 +36,20 @@ (response/content-type "text/html"))) (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] (hello req)) @@ -37,11 +57,22 @@ (def router (reitit.ring/router #{["/" {:get hello}] - ["/n/:slug" {:get node-by-slug - #_#_#_#_:coercion reitit.coercion.spec/coercion - :parameters {:path {:slug ::slug/slug}}}] + ["/n/:slug" {:get + {:handler node-by-slug + :parameters + {:path {:slug (st/spec {:spec ::slug/slug})}}}}] ["/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] (if-let [match (r/match-by-path router path)] diff --git a/publisher/src/net/deertopia/publisher/slug.clj b/publisher/src/net/deertopia/publisher/slug.clj index d5d2a11..a727e39 100644 --- a/publisher/src/net/deertopia/publisher/slug.clj +++ b/publisher/src/net/deertopia/publisher/slug.clj @@ -60,7 +60,6 @@ "invalid slug") (->Slug string)) -(defn slug? [s] - (some? (from-string s))) - -(s/def ::slug slug?) +(s/def ::slug + (s/conformer #(or (some-> % from-string) + ::s/invalid)))