mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 17:01:11 +00:00
fix: fix bug where http ring handler would cause :path to be applied twice
This commit is contained in:
parent
f466271e15
commit
f1ec7bbe8e
2 changed files with 19 additions and 2 deletions
|
|
@ -133,7 +133,7 @@
|
||||||
(interceptor/queue executor))
|
(interceptor/queue executor))
|
||||||
router-opts (-> (r/options router)
|
router-opts (-> (r/options router)
|
||||||
(assoc ::interceptor/queue (partial interceptor/queue executor))
|
(assoc ::interceptor/queue (partial interceptor/queue executor))
|
||||||
(dissoc :data) ; data is already merged into routes
|
(dissoc :data :path) ; data and path already take effect in routes
|
||||||
(cond-> (seq interceptors)
|
(cond-> (seq interceptors)
|
||||||
(update-in [:data :interceptors] (partial into (vec interceptors)))))
|
(update-in [:data :interceptors] (partial into (vec interceptors)))))
|
||||||
router (reitit.http/router (r/routes router) router-opts) ;; will re-compile the interceptors
|
router (reitit.http/router (r/routes router) router-opts) ;; will re-compile the interceptors
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,24 @@
|
||||||
|
|
||||||
(testing "all named routes can be matched"
|
(testing "all named routes can be matched"
|
||||||
(doseq [name (r/route-names router)]
|
(doseq [name (r/route-names router)]
|
||||||
(is (= name (-> (r/match-by-name router name) :data :name))))))))
|
(is (= name (-> (r/match-by-name router name) :data :name)))))))
|
||||||
|
|
||||||
|
(testing "path prefixed routes"
|
||||||
|
(let [router (http/router
|
||||||
|
[["/all" {:handler handler}]
|
||||||
|
["/get" {:get {:handler handler}}]
|
||||||
|
["/users" {:get handler}]]
|
||||||
|
{:path "/api"})
|
||||||
|
app (http/ring-handler router nil {:executor sieppari/executor})]
|
||||||
|
|
||||||
|
(testing "router can be extracted"
|
||||||
|
(is (= (r/routes router)
|
||||||
|
(r/routes (http/get-router app)))))
|
||||||
|
|
||||||
|
(testing "handler resolved original router routes"
|
||||||
|
(doseq [router-path (mapv first (r/routes router))]
|
||||||
|
(is (= 200
|
||||||
|
(:status (app {:uri router-path :request-method :get})))))))))
|
||||||
|
|
||||||
(def enforce-roles-interceptor
|
(def enforce-roles-interceptor
|
||||||
{:enter (fn [{{::keys [roles] :as request} :request :as ctx}]
|
{:enter (fn [{{::keys [roles] :as request} :request :as ctx}]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue