mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Fix #216
This commit is contained in:
parent
bd11b6032d
commit
b1bef1c1cc
5 changed files with 45 additions and 29 deletions
|
|
@ -9,6 +9,14 @@
|
||||||
controller is interested in, as data, which should cover most
|
controller is interested in, as data, which should cover most
|
||||||
use cases: `{:start start-fn, :parameters {:path [:foo-id]}}`
|
use cases: `{:start start-fn, :parameters {:path [:foo-id]}}`
|
||||||
|
|
||||||
|
## `reitit-ring`
|
||||||
|
|
||||||
|
* Allow Middleware to compile to `nil` with Middleware Registries, fixes to [#216](https://github.com/metosin/reitit/issues/216).
|
||||||
|
|
||||||
|
## `reitit-http`
|
||||||
|
|
||||||
|
* Allow Interceptors to compile to `nil` with Interceptor Registries, related to [#216](https://github.com/metosin/reitit/issues/216).
|
||||||
|
|
||||||
## 0.2.13 (2019-01-26)
|
## 0.2.13 (2019-01-26)
|
||||||
|
|
||||||
* Don't throw `StringIndexOutOfBoundsException` with empty path lookup on wildcard paths, fixes [#209](https://github.com/metosin/reitit/issues/209)
|
* Don't throw `StringIndexOutOfBoundsException` with empty path lookup on wildcard paths, fixes [#209](https://github.com/metosin/reitit/issues/209)
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,20 @@
|
||||||
#?(:clj clojure.lang.Keyword
|
#?(:clj clojure.lang.Keyword
|
||||||
:cljs cljs.core.Keyword)
|
:cljs cljs.core.Keyword)
|
||||||
(into-interceptor [this data {:keys [::registry] :as opts}]
|
(into-interceptor [this data {:keys [::registry] :as opts}]
|
||||||
(or (if-let [interceptor (if registry (registry this))]
|
(if-let [interceptor (if registry (registry this))]
|
||||||
(into-interceptor interceptor data opts))
|
(into-interceptor interceptor data opts)
|
||||||
(throw
|
(throw
|
||||||
(ex-info
|
(ex-info
|
||||||
(str
|
(str
|
||||||
"Interceptor " this " not found in registry.\n\n"
|
"Interceptor " this " not found in registry.\n\n"
|
||||||
(if (seq registry)
|
(if (seq registry)
|
||||||
(str
|
(str
|
||||||
"Available interceptors in registry:\n"
|
"Available interceptors in registry:\n"
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(pprint/print-table [:id :description] (for [[k v] registry] {:id k :description v}))))
|
(pprint/print-table [:id :description] (for [[k v] registry] {:id k :description v}))))
|
||||||
"see [reitit.interceptor/router] on how to add interceptor to the registry.\n") "\n")
|
"see [reitit.interceptor/router] on how to add interceptor to the registry.\n") "\n")
|
||||||
{:id this
|
{:id this
|
||||||
:registry registry}))))
|
:registry registry}))))
|
||||||
|
|
||||||
#?(:clj clojure.lang.APersistentVector
|
#?(:clj clojure.lang.APersistentVector
|
||||||
:cljs cljs.core.PersistentVector)
|
:cljs cljs.core.PersistentVector)
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,20 @@
|
||||||
#?(:clj clojure.lang.Keyword
|
#?(:clj clojure.lang.Keyword
|
||||||
:cljs cljs.core.Keyword)
|
:cljs cljs.core.Keyword)
|
||||||
(into-middleware [this data {:keys [::registry] :as opts}]
|
(into-middleware [this data {:keys [::registry] :as opts}]
|
||||||
(or (if-let [middleware (if registry (registry this))]
|
(if-let [middleware (if registry (registry this))]
|
||||||
(into-middleware middleware data opts))
|
(into-middleware middleware data opts)
|
||||||
(throw
|
(throw
|
||||||
(ex-info
|
(ex-info
|
||||||
(str
|
(str
|
||||||
"Middleware " this " not found in registry.\n\n"
|
"Middleware " this " not found in registry.\n\n"
|
||||||
(if (seq registry)
|
(if (seq registry)
|
||||||
(str
|
(str
|
||||||
"Available middleware in registry:\n"
|
"Available middleware in registry:\n"
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(pprint/print-table [:id :description] (for [[k v] registry] {:id k :description v}))))
|
(pprint/print-table [:id :description] (for [[k v] registry] {:id k :description v}))))
|
||||||
"see [reitit.middleware/router] on how to add middleware to the registry.\n") "\n")
|
"see [reitit.middleware/router] on how to add middleware to the registry.\n") "\n")
|
||||||
{:id this
|
{:id this
|
||||||
:registry registry}))))
|
:registry registry}))))
|
||||||
|
|
||||||
#?(:clj clojure.lang.APersistentVector
|
#?(:clj clojure.lang.APersistentVector
|
||||||
:cljs cljs.core.PersistentVector)
|
:cljs cljs.core.PersistentVector)
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,10 @@
|
||||||
#"Interceptor :enter not found in registry"
|
#"Interceptor :enter not found in registry"
|
||||||
(create [:enter]))))
|
(create [:enter]))))
|
||||||
|
|
||||||
|
(testing "existing keyword, compiling to nil"
|
||||||
|
(let [app (create [:enter] {::interceptor/registry {:enter {:compile (constantly nil)}}})]
|
||||||
|
(is (= [:ok] (app ctx)))))
|
||||||
|
|
||||||
(testing "as map"
|
(testing "as map"
|
||||||
(reset! calls 0)
|
(reset! calls 0)
|
||||||
(let [app (create [{:enter (:enter (enter :value))}])]
|
(let [app (create [{:enter (:enter (enter :value))}])]
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
(defn create
|
(defn create
|
||||||
([middleware]
|
([middleware]
|
||||||
(create middleware nil))
|
(create middleware nil))
|
||||||
([middleware opts]
|
([middleware opts]
|
||||||
(middleware/chain
|
(middleware/chain
|
||||||
middleware
|
middleware
|
||||||
|
|
@ -65,6 +65,10 @@
|
||||||
#"Middleware :wrap not found in registry"
|
#"Middleware :wrap not found in registry"
|
||||||
(create [:wrap]))))
|
(create [:wrap]))))
|
||||||
|
|
||||||
|
(testing "existing keyword, compiling to nil"
|
||||||
|
(let [app (create [:wrap] {::middleware/registry {:wrap {:compile (constantly nil)}}})]
|
||||||
|
(is (= [:ok] (app request)))))
|
||||||
|
|
||||||
(testing "as function vector with value(s)"
|
(testing "as function vector with value(s)"
|
||||||
(reset! calls 0)
|
(reset! calls 0)
|
||||||
(let [app (create [[wrap :value]])]
|
(let [app (create [[wrap :value]])]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue