feat: reitit.core/Expand for Vars

This commit is contained in:
Joel Kaasinen 2024-03-15 09:21:51 +02:00
parent 659e96e780
commit 5d30a73bad
2 changed files with 12 additions and 1 deletions

View file

@ -28,6 +28,10 @@
:cljs function) :cljs function)
(expand [this _] {:handler this}) (expand [this _] {:handler this})
#?(:clj clojure.lang.Var
:cljs cljs.core.Var)
(expand [this _] {:handler this})
nil nil
(expand [_ _])) (expand [_ _]))

View file

@ -6,6 +6,9 @@
(:import (clojure.lang ExceptionInfo) (:import (clojure.lang ExceptionInfo)
(reitit.core Router)))) (reitit.core Router))))
(defn- var-handler [& _]
"var-handler")
(deftest reitit-test (deftest reitit-test
(testing "routers handling wildcard paths" (testing "routers handling wildcard paths"
@ -245,7 +248,11 @@
(let [router (r/router ["/ping" (constantly "ok")]) (let [router (r/router ["/ping" (constantly "ok")])
{:keys [result]} (r/match-by-path router "/ping")] {:keys [result]} (r/match-by-path router "/ping")]
(is result) (is result)
(is (= "ok" (result)))))) (is (= "ok" (result))))
(testing "var handler gets expanded"
(let [router (r/router ["/ping" #'var-handler])
{:keys [result]} (r/match-by-path router "/ping")]
(is (= #'var-handler result))))))
(testing "custom router" (testing "custom router"
(let [router (r/router ["/ping"] {:router (fn [_ _] (let [router (r/router ["/ping"] {:router (fn [_ _]