mirror of
https://github.com/metosin/reitit.git
synced 2026-02-02 02:30:35 +00:00
Custom handler for resource 404
This commit is contained in:
parent
f5ee149929
commit
e84b25d4ac
1 changed files with 4 additions and 4 deletions
|
|
@ -160,11 +160,12 @@
|
||||||
| :index-files | optional vector of index-files to look in a resource directory, defaults to `[\"index.html\"]`"
|
| :index-files | optional vector of index-files to look in a resource directory, defaults to `[\"index.html\"]`"
|
||||||
([]
|
([]
|
||||||
(create-resource-handler nil))
|
(create-resource-handler nil))
|
||||||
([{:keys [parameter root path loader allow-symlinks? index-files paths]
|
([{:keys [parameter root path loader allow-symlinks? index-files paths not-found-handler]
|
||||||
:or {parameter (keyword "")
|
:or {parameter (keyword "")
|
||||||
root "public"
|
root "public"
|
||||||
index-files ["index.html"]
|
index-files ["index.html"]
|
||||||
paths (constantly nil)}}]
|
paths (constantly nil)
|
||||||
|
not-found-handler (constantly {:status 404, :body "", :headers {}})}}]
|
||||||
(let [options {:root root, :loader loader, :allow-symlinks? allow-symlinks?}
|
(let [options {:root root, :loader loader, :allow-symlinks? allow-symlinks?}
|
||||||
path-size (count path)
|
path-size (count path)
|
||||||
create (fn [handler]
|
create (fn [handler]
|
||||||
|
|
@ -193,8 +194,7 @@
|
||||||
(let [uri (:uri request)
|
(let [uri (:uri request)
|
||||||
path (-> request :path-params parameter)]
|
path (-> request :path-params parameter)]
|
||||||
(or (path-or-index-response path uri)
|
(or (path-or-index-response path uri)
|
||||||
;; TODO: use generic not-found handler
|
(not-found-handler request)))))]
|
||||||
{:status 404}))))]
|
|
||||||
(create handler)))))
|
(create handler)))))
|
||||||
|
|
||||||
(defn ring-handler
|
(defn ring-handler
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue