mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Support not-found-handler with path in resource handler (#464)
This commit is contained in:
parent
03f029e536
commit
902b33f004
2 changed files with 12 additions and 6 deletions
|
|
@ -222,7 +222,8 @@
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(let [uri (:uri request)]
|
(let [uri (:uri request)]
|
||||||
(if (str/starts-with? uri path)
|
(if (str/starts-with? uri path)
|
||||||
(path-or-index-response (subs uri path-size) uri))))
|
(or (path-or-index-response (subs uri path-size) uri)
|
||||||
|
(not-found-handler request)))))
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(let [uri (:uri request)
|
(let [uri (:uri request)
|
||||||
path (-> request :path-params parameter)]
|
path (-> request :path-params parameter)]
|
||||||
|
|
|
||||||
|
|
@ -547,7 +547,7 @@
|
||||||
(let [app (ring/ring-handler
|
(let [app (ring/ring-handler
|
||||||
(ring/router [])
|
(ring/router [])
|
||||||
(ring/routes
|
(ring/routes
|
||||||
(create {:path "/"})
|
(create {:path "/" :not-found-handler (fn [x] {:status 404 :body "resource-handler"})})
|
||||||
(ring/create-default-handler)))]
|
(ring/create-default-handler)))]
|
||||||
(testing test
|
(testing test
|
||||||
(testing "different file-types"
|
(testing "different file-types"
|
||||||
|
|
@ -568,7 +568,8 @@
|
||||||
|
|
||||||
(testing "not found"
|
(testing "not found"
|
||||||
(let [response (app (request "/not-found"))]
|
(let [response (app (request "/not-found"))]
|
||||||
(is (= 404 (:status response)))))
|
(is (= 404 (:status response)))
|
||||||
|
(is (= "resource-handler" (:body response)))))
|
||||||
|
|
||||||
(testing "3-arity"
|
(testing "3-arity"
|
||||||
(let [result (atom nil)
|
(let [result (atom nil)
|
||||||
|
|
@ -583,7 +584,7 @@
|
||||||
(let [app (ring/ring-handler
|
(let [app (ring/ring-handler
|
||||||
(ring/router [])
|
(ring/router [])
|
||||||
(ring/routes
|
(ring/routes
|
||||||
(create {:path "/files"})
|
(create {:path "/files" :not-found-handler (fn [x] {:status 404 :body "resource-handler"})})
|
||||||
(ring/create-default-handler)))
|
(ring/create-default-handler)))
|
||||||
request #(request (str "/files" %))
|
request #(request (str "/files" %))
|
||||||
redirect #(redirect (str "/files" %))]
|
redirect #(redirect (str "/files" %))]
|
||||||
|
|
@ -605,8 +606,12 @@
|
||||||
(is (= (redirect "/docs/index.html") response))))
|
(is (= (redirect "/docs/index.html") response))))
|
||||||
|
|
||||||
(testing "not found"
|
(testing "not found"
|
||||||
(let [response (app (request "/not-found"))]
|
(let [response (app {:uri "/not-found" :request-method :get})]
|
||||||
(is (= 404 (:status response)))))
|
(is (= 404 (:status response)))
|
||||||
|
(is (= "" (:body response))))
|
||||||
|
(let [response (app {:uri "/files/not-found" :request-method :get})]
|
||||||
|
(is (= 404 (:status response)))
|
||||||
|
(is (= "resource-handler" (:body response)))))
|
||||||
|
|
||||||
(testing "3-arity"
|
(testing "3-arity"
|
||||||
(let [result (atom nil)
|
(let [result (atom nil)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue