From e84b25d4aca5e3175436b4fa5deff026068bd687 Mon Sep 17 00:00:00 2001 From: Vale Date: Wed, 10 Oct 2018 13:57:51 +0900 Subject: [PATCH 1/2] Custom handler for resource 404 --- modules/reitit-ring/src/reitit/ring.cljc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index fdb44e29..9a817188 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -160,11 +160,12 @@ | :index-files | optional vector of index-files to look in a resource directory, defaults to `[\"index.html\"]`" ([] (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 +194,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 From 21c888b8bc1640093dce8eeae568aa3b95d7656e Mon Sep 17 00:00:00 2001 From: Vale Date: Wed, 10 Oct 2018 13:57:59 +0900 Subject: [PATCH 2/2] Update docstring --- modules/reitit-ring/src/reitit/ring.cljc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/reitit-ring/src/reitit/ring.cljc b/modules/reitit-ring/src/reitit/ring.cljc index 9a817188..933ba065 100644 --- a/modules/reitit-ring/src/reitit/ring.cljc +++ b/modules/reitit-ring/src/reitit/ring.cljc @@ -151,13 +151,14 @@ (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 not-found-handler]