mirror of
https://github.com/metosin/reitit.git
synced 2025-12-23 10:41:10 +00:00
Merge pull request #155 from valerauko/resource-404
Custom handler for resource 404
This commit is contained in:
commit
a77a583c09
1 changed files with 12 additions and 11 deletions
|
|
@ -151,20 +151,22 @@
|
|||
(defn create-resource-handler
|
||||
"A ring handler for serving classpath resources, configured via options:
|
||||
|
||||
| key | description |
|
||||
| -----------------|-------------|
|
||||
| :parameter | optional name of the wildcard parameter, defaults to unnamed keyword `:`
|
||||
| :root | optional resource root, defaults to `\"public\"`
|
||||
| :path | optional path to mount the handler to. Works only if mounted outside of a router.
|
||||
| :loader | optional class loader to resolve the resources
|
||||
| :index-files | optional vector of index-files to look in a resource directory, defaults to `[\"index.html\"]`"
|
||||
| key | description |
|
||||
| -------------------|-------------|
|
||||
| :parameter | optional name of the wildcard parameter, defaults to unnamed keyword `:`
|
||||
| :root | optional resource root, defaults to `\"public\"`
|
||||
| :path | optional path to mount the handler to. Works only if mounted outside of a router.
|
||||
| :loader | optional class loader to resolve the resources
|
||||
| :index-files | optional vector of index-files to look in a resource directory, defaults to `[\"index.html\"]`
|
||||
| :not-found-handler | optional handler function to use if the requested resource is missing (404 Not Found)"
|
||||
([]
|
||||
(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 "")
|
||||
root "public"
|
||||
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?}
|
||||
path-size (count path)
|
||||
create (fn [handler]
|
||||
|
|
@ -193,8 +195,7 @@
|
|||
(let [uri (:uri request)
|
||||
path (-> request :path-params parameter)]
|
||||
(or (path-or-index-response path uri)
|
||||
;; TODO: use generic not-found handler
|
||||
{:status 404}))))]
|
||||
(not-found-handler request)))))]
|
||||
(create handler)))))
|
||||
|
||||
(defn ring-handler
|
||||
|
|
|
|||
Loading…
Reference in a new issue