mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01: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
|
||||
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)
|
||||
|
||||
* 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
|
||||
:cljs cljs.core.Keyword)
|
||||
(into-interceptor [this data {:keys [::registry] :as opts}]
|
||||
(or (if-let [interceptor (if registry (registry this))]
|
||||
(into-interceptor interceptor data opts))
|
||||
(throw
|
||||
(ex-info
|
||||
(str
|
||||
"Interceptor " this " not found in registry.\n\n"
|
||||
(if (seq registry)
|
||||
(str
|
||||
"Available interceptors in registry:\n"
|
||||
(with-out-str
|
||||
(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")
|
||||
{:id this
|
||||
:registry registry}))))
|
||||
(if-let [interceptor (if registry (registry this))]
|
||||
(into-interceptor interceptor data opts)
|
||||
(throw
|
||||
(ex-info
|
||||
(str
|
||||
"Interceptor " this " not found in registry.\n\n"
|
||||
(if (seq registry)
|
||||
(str
|
||||
"Available interceptors in registry:\n"
|
||||
(with-out-str
|
||||
(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")
|
||||
{:id this
|
||||
:registry registry}))))
|
||||
|
||||
#?(:clj clojure.lang.APersistentVector
|
||||
:cljs cljs.core.PersistentVector)
|
||||
|
|
|
|||
|
|
@ -17,20 +17,20 @@
|
|||
#?(:clj clojure.lang.Keyword
|
||||
:cljs cljs.core.Keyword)
|
||||
(into-middleware [this data {:keys [::registry] :as opts}]
|
||||
(or (if-let [middleware (if registry (registry this))]
|
||||
(into-middleware middleware data opts))
|
||||
(throw
|
||||
(ex-info
|
||||
(str
|
||||
"Middleware " this " not found in registry.\n\n"
|
||||
(if (seq registry)
|
||||
(str
|
||||
"Available middleware in registry:\n"
|
||||
(with-out-str
|
||||
(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")
|
||||
{:id this
|
||||
:registry registry}))))
|
||||
(if-let [middleware (if registry (registry this))]
|
||||
(into-middleware middleware data opts)
|
||||
(throw
|
||||
(ex-info
|
||||
(str
|
||||
"Middleware " this " not found in registry.\n\n"
|
||||
(if (seq registry)
|
||||
(str
|
||||
"Available middleware in registry:\n"
|
||||
(with-out-str
|
||||
(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")
|
||||
{:id this
|
||||
:registry registry}))))
|
||||
|
||||
#?(:clj clojure.lang.APersistentVector
|
||||
:cljs cljs.core.PersistentVector)
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@
|
|||
#"Interceptor :enter not found in registry"
|
||||
(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"
|
||||
(reset! calls 0)
|
||||
(let [app (create [{:enter (:enter (enter :value))}])]
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
(defn create
|
||||
([middleware]
|
||||
(create middleware nil))
|
||||
(create middleware nil))
|
||||
([middleware opts]
|
||||
(middleware/chain
|
||||
middleware
|
||||
|
|
@ -65,6 +65,10 @@
|
|||
#"Middleware :wrap not found in registry"
|
||||
(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)"
|
||||
(reset! calls 0)
|
||||
(let [app (create [[wrap :value]])]
|
||||
|
|
|
|||
Loading…
Reference in a new issue