Wrap an app such that the directory at the given root-path is checked for a
static file with which to respond to the request, proxying the request to the
wrapped app if such a file does not exist.
(defn wrap-file
"Wrap an app such that the directory at the given root-path is checked for a
static file with which to respond to the request, proxying the request to the
wrapped app if such a file does not exist."
[app #^String root-path]
(ensure-dir root-path)
(fn [req]
(if-not (= :get (:request-method req))
(app req)
(let [path (.substring (codec/url-decode (:uri req)) 1)]
(or
(response/file-response path
{:root root-path :index-files? true :html-files? true})
(app req))))))
Comments top
No comments for wrap-file. Log in to add a comment.