biff.middleware

Ring middleware.

use-default-middleware

(use-default-middleware {:keys [biff.middleware/cookie-secret biff.middleware/secure biff.middleware/spa-path biff/on-error], :or {on-error (constantly {:status 500, :headers {"Content-Type" "text/plain"}, :body "Internal server error."}), secure true}, :as sys})
TODO add docstring

wrap-defaults

(wrap-defaults handler {:keys [session-store cookie-session-secret secure session-max-age on-error env], :or {session-max-age (* 60 60 24 30), secure true}, :as opts})
TODO add docstring

wrap-env

(wrap-env handler env)
Merges env into requests.

wrap-flat-keys

(wrap-flat-keys handler)
Lets handler use flattened versions of session, params, headers and cookies.

Adds :session/* and :params/* keys to the request, and nests :headers/* and
:cookies/* keys in the response. For example:

{:params {:foo "bar"}}
=> {:params/foo "bar"}

{:headers/content-type "text/html"}
=> {:headers {:content-type "text/html"}}

wrap-index-files

(wrap-index-files handler {:keys [index-files], :or {index-files ["index.html"]}})
If handler returns nil, try again with each index file appended to the URI.

wrap-internal-error

(wrap-internal-error handler {:keys [on-error]})
Catches exceptions and calls on-error instead.

on-error should accept a request map with :status and :ex (exception) keys.
If the exception's ex-data is an anomaly, get the status from
biff.util/anom->http-status; otherwise it will be 500.

Also prints exception info (stack trace for 500s, message + ex-data
otherwise).

wrap-log-requests

(wrap-log-requests handler)
Prints status, request method and response status for each request.

wrap-resource

(wrap-resource handler {:keys [root index-files spa-path spa-exclude-paths spa-client-paths], :or {root "public", index-files ["index.html"], spa-exclude-paths ["/js/" "/css/" "/cljs/" "/img/" "/assets/" "/favicon.ico"]}})
Serves static resources with ring.middleware.resource/wrap-resource-request.

root:              The resource root from which static files should be
                   served.
index-files:       See wrap-index-files.
spa-path:          If set, replace 404 responses with this file.
spa-exclude-paths: Ignore spa-path if the request URI starts with one of
                   these.
spa-client-paths:  A set of SPA routes. If set, ignore spa-path unless the
                   request URI is one of these. Takes precedence over
                   spa-exclude-paths.