(wrap-resource handler root-path)
(wrap-resource handler root-path options)
Middleware that first checks to see whether the request map matches a static
resource. If it does, the resource is returned in a response map, otherwise
the request map is passed onto the handler. The root-path argument will be
added to the beginning of the resource path.
Accepts the following options:
:loader - resolve the resource using this class loader
:allow-symlinks? - allow symlinks that lead to paths outside the root
classpath directories (defaults to false)
Source
(defn wrap-resource
"Middleware that first checks to see whether the request map matches a static
resource. If it does, the resource is returned in a response map, otherwise
the request map is passed onto the handler. The root-path argument will be
added to the beginning of the resource path.
Accepts the following options:
:loader - resolve the resource using this class loader
:allow-symlinks? - allow symlinks that lead to paths outside the root
classpath directories (defaults to false)"
([handler root-path]
(wrap-resource handler root-path {}))
([handler root-path options]
(fn
([request]
(or (resource-request request root-path options)
(handler request)))
([request respond raise]
(if-let [response (resource-request request root-path options)]
(respond response)
(handler request respond raise))))))