mirror of
https://github.com/metosin/reitit.git
synced 2026-02-03 19:03:12 +00:00
Inject Match and Router under reitit.core ns in ring
This commit is contained in:
parent
cb5e4d1177
commit
3005e04a6e
1 changed files with 13 additions and 9 deletions
|
|
@ -32,7 +32,7 @@
|
||||||
([{:keys [not-found method-not-allowed not-acceptable]}]
|
([{:keys [not-found method-not-allowed not-acceptable]}]
|
||||||
(fn
|
(fn
|
||||||
([request]
|
([request]
|
||||||
(if-let [match (::match request)]
|
(if-let [match (::r/match request)]
|
||||||
(let [method (:request-method request :any)
|
(let [method (:request-method request :any)
|
||||||
result (:result match)
|
result (:result match)
|
||||||
handler? (or (-> result method :handler) (-> result :any :handler))
|
handler? (or (-> result method :handler) (-> result :any :handler))
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
(error-handler request))
|
(error-handler request))
|
||||||
(not-found request)))
|
(not-found request)))
|
||||||
([request respond _]
|
([request respond _]
|
||||||
(if-let [match (::match request)]
|
(if-let [match (::r/match request)]
|
||||||
(let [method (:request-method request :any)
|
(let [method (:request-method request :any)
|
||||||
result (:result match)
|
result (:result match)
|
||||||
handler? (or (-> result method :handler) (-> result :any :handler))
|
handler? (or (-> result method :handler) (-> result :any :handler))
|
||||||
|
|
@ -66,8 +66,10 @@
|
||||||
result (:result match)
|
result (:result match)
|
||||||
handler (or (-> result method :handler)
|
handler (or (-> result method :handler)
|
||||||
(-> result :any (:handler default-handler)))
|
(-> result :any (:handler default-handler)))
|
||||||
request (cond-> (impl/fast-assoc request ::match match)
|
request (-> request
|
||||||
(seq path-params) (impl/fast-assoc :path-params path-params))
|
(impl/fast-assoc ::r/match match)
|
||||||
|
(impl/fast-assoc ::r/router router)
|
||||||
|
(cond-> (seq path-params) (impl/fast-assoc :path-params path-params)))
|
||||||
response (handler request)]
|
response (handler request)]
|
||||||
(if (nil? response)
|
(if (nil? response)
|
||||||
(default-handler request)
|
(default-handler request)
|
||||||
|
|
@ -80,17 +82,19 @@
|
||||||
result (:result match)
|
result (:result match)
|
||||||
handler (or (-> result method :handler)
|
handler (or (-> result method :handler)
|
||||||
(-> result :any (:handler default-handler)))
|
(-> result :any (:handler default-handler)))
|
||||||
request (cond-> (impl/fast-assoc request ::match match)
|
request (-> request
|
||||||
(seq path-params) (impl/fast-assoc :path-params path-params))]
|
(impl/fast-assoc ::r/match match)
|
||||||
|
(impl/fast-assoc ::r/router router)
|
||||||
|
(cond-> (seq path-params) (impl/fast-assoc :path-params path-params)))]
|
||||||
(handler request respond raise))
|
(handler request respond raise))
|
||||||
(default-handler request respond raise))))
|
(default-handler request respond raise))))
|
||||||
{::router router}))))
|
{::r/router router}))))
|
||||||
|
|
||||||
(defn get-router [handler]
|
(defn get-router [handler]
|
||||||
(some-> handler meta ::router))
|
(-> handler meta ::r/router))
|
||||||
|
|
||||||
(defn get-match [request]
|
(defn get-match [request]
|
||||||
(::match request))
|
(::r/match request))
|
||||||
|
|
||||||
(defn coerce-handler [[path data] {:keys [expand] :as opts}]
|
(defn coerce-handler [[path data] {:keys [expand] :as opts}]
|
||||||
[path (reduce
|
[path (reduce
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue