Liking cljdoc? Tell your friends :D

com.biffweb


add-secondsclj

(add-seconds date seconds)

Returns a new java.util.Date with the given number of seconds added.

Returns a new java.util.Date with the given number of seconds added.
raw docstring

anomclj

(anom category & [message & [opts]])

Constructs an anomaly.

Example: (anom :incorrect "Invalid parameter" {:info "x should be an integer"})

See https://github.com/cognitect-labs/anomalies

Constructs an anomaly.

Example: (anom :incorrect
               "Invalid parameter"
               {:info "x should be an integer"})

See https://github.com/cognitect-labs/anomalies
raw docstring

anomaly?clj

(anomaly? x)

Returns true if x is an anomaly.

See https://github.com/cognitect-labs/anomalies

Returns true if x is an anomaly.

See https://github.com/cognitect-labs/anomalies
raw docstring

assoc-dbclj

(assoc-db {:keys [biff.xtdb/node] :as sys})

Sets :biff/db on the system map to (xt/db node)

Sets :biff/db on the system map to (xt/db node)
raw docstring

base-htmlclj

(base-html {:base/keys [title description lang image icon url canonical
                        font-families head]
            :as opts}
           &
           contents)

Wraps contents in an :html and :body element with various metadata set.

font-families: A collection of families to request from Google fonts (see g-fonts). head: Additional Rum elements to include inside the head.

Wraps contents in an :html and :body element with various metadata set.

font-families:  A collection of families to request from Google fonts (see g-fonts).
head:           Additional Rum elements to include inside the head.
raw docstring

base64-decodeclj

(base64-decode string)

Converts a base64 string to a byte array.

Converts a base64 string to a byte array.
raw docstring

base64-encodeclj

(base64-encode bytes)

Converts a byte array to a base64 string.

Converts a byte array to a base64 string.
raw docstring

between-hours?clj

(between-hours? t h1 h2)

Returns true if t is between the hours of h1 and h2 UTC.

For example: (between-hours? #inst "2022-03-27T14:18:34.360-00:00" 14 16) => true

Returns true if t is between the hours of h1 and h2 UTC.

For example:
(between-hours? #inst "2022-03-27T14:18:34.360-00:00" 14 16)
=> true
raw docstring

catchallcljmacro

(catchall & body)

Wraps body in (try ... (catch Exception _ nil))

Wraps body in (try ... (catch Exception _ nil))
raw docstring

crop-dateclj

(crop-date date format)

Passes date through format-date and parse-date, in order to remove any information not captured in the format.

For example: (crop-date #inst "2022-03-27T09:13:34.182-00:00" "yyyy") => #inst "2022-01-01T08:00:00.000-00:00"

Passes date through format-date and parse-date, in order to remove any
information not captured in the format.

For example:
(crop-date #inst "2022-03-27T09:13:34.182-00:00" "yyyy")
=> #inst "2022-01-01T08:00:00.000-00:00"
raw docstring

crop-dayclj

(crop-day date)

Same as (crop-date "yyyy-MM-dd")

Same as (crop-date "yyyy-MM-dd")
raw docstring

elapsed?clj

(elapsed? t1 t2 x unit)

Returns true if t2 occurs at least x units after t1.

unit can be :seconds, :minutes, :hours, :days, or :weeks.

Returns true if t2 occurs at least x units after t1.

unit can be :seconds, :minutes, :hours, :days, or :weeks.
raw docstring

emdashclj

A Rum data structure for an em dash.

A Rum data structure for an em dash.
raw docstring

endashclj

A Rum data structure for an en dash.

A Rum data structure for an en dash.
raw docstring

eval-files!clj

(eval-files! {:keys [biff/eval-paths] :or {eval-paths ["src"]}})

Evaluates any modified files and their dependents via clojure.tools.namespace.

Evaluates any modified files and their dependents via clojure.tools.namespace.
raw docstring

export-rumclj

(export-rum pages dir)

Generate HTML files and write them to a directory.

pages: A map from paths to Rum data structures, e.g. {"/" [:div "hello"]}. Paths that end in / will have index.html appended to them. dir: A path to the root directory where the files should be saved, e.g. "target/resources/public".

Generate HTML files and write them to a directory.

pages:  A map from paths to Rum data structures, e.g.
        {"/" [:div "hello"]}. Paths that end in / will have index.html
        appended to them.
dir:    A path to the root directory where the files should be saved, e.g.
        "target/resources/public".
raw docstring

fix-printcljmacro

(fix-print & body)

Ensures that print output doesn't get swallowed by e.g. an editor nrepl plugin.

Binds out, err and flush-on-newline to their root values.

(fix-print (println "hello"))

Ensures that print output doesn't get swallowed by e.g. an editor nrepl plugin.

Binds *out*, *err* and *flush-on-newline* to their root values.

(fix-print
  (println "hello"))
raw docstring

formclj

(form {:keys [hidden] :as opts} & body)

Returns a [:form ...] element.

hidden: A map from names to values, which will be converted to [:input {:type "hidden" ...}] fields. opts: Options for the :form element (with hidden removed).

Sets :method to "post" by default, and includes a CSRF token (via ring.middleware.anti-forgery/anti-forgery-token).

Returns a [:form ...] element.

hidden:  A map from names to values, which will be converted to
         [:input {:type "hidden" ...}] fields.
opts:    Options for the :form element (with hidden removed).

Sets :method to "post" by default, and includes a CSRF token (via
ring.middleware.anti-forgery/*anti-forgery-token*).
raw docstring

format-dateclj

(format-date date & [format])

Formats date using java.text.SimpleDateFormat.

If format isn't provided, uses rfc3339.

Formats date using java.text.SimpleDateFormat.

If format isn't provided, uses rfc3339.
raw docstring

g-fontsclj

(g-fonts families)

Returns a link element for requesting families from Google fonts.

For example: (g-fonts ["Nunito+Sans:wght@900"]) => [:link {:rel "stylesheet", :href ...}]

Returns a link element for requesting families from Google fonts.

For example:
(g-fonts ["Nunito+Sans:wght@900"])
=> [:link {:rel "stylesheet", :href ...}]
raw docstring

generate-secretclj

(generate-secret length)

Generates a random byte array and returns it as a base64 string.

The bytes are generated with buddy.core.nonce/random-bytes, which uses a secure random number generator.

Generates a random byte array and returns it as a base64 string.

The bytes are generated with buddy.core.nonce/random-bytes, which uses a
secure random number generator.
raw docstring

jwt-decryptclj

(jwt-decrypt token secret)

Convenience wrapper for buddy.sign.jwt/decrypt.

token is a string as returned by jwt-encrypt. secret is a base64-encoded string that was used to encrypt token. Returns the claims passed to jwt-encrypt. Returns nil if the token is invalid or expired.

Convenience wrapper for buddy.sign.jwt/decrypt.

token is a string as returned by jwt-encrypt. secret is a base64-encoded
string that was used to encrypt token. Returns the claims passed to
jwt-encrypt. Returns nil if the token is invalid or expired.
raw docstring

jwt-encryptclj

(jwt-encrypt {:keys [exp-in] :as claims} secret)

Convenience wrapper for buddy.sign.jwt/encrypt.

Returns a string token. secret is a base64-encoded string used to encrypt the token. A secret can be generated with (com.biffweb/generate-secret 32). exp-in is the number of seconds in the future at which the token should expire. claims is passed to buddy.sign.jwt/encrypt as-is, except that :exp is set based on exp-in.

Convenience wrapper for buddy.sign.jwt/encrypt.

Returns a string token. secret is a base64-encoded string used to encrypt the
token. A secret can be generated with (com.biffweb/generate-secret 32).
exp-in is the number of seconds in the future at which the token should
expire. claims is passed to buddy.sign.jwt/encrypt as-is, except that :exp is
set based on exp-in.
raw docstring

lazy-qclj

(lazy-q db query & args)

Calls xtdb.api/open-q and passes a lazy seq of the results to a function.

Accepts the same arguments as xtdb.api/open-q, except the last argument is a function which must process the results eagerly. Also includes the same functionality as biff/q.

Calls xtdb.api/open-q and passes a lazy seq of the results to a function.

Accepts the same arguments as xtdb.api/open-q, except the last argument is a
function which must process the results eagerly. Also includes the same
functionality as biff/q.
raw docstring

letdcljmacro

(letd bindings & body)

Like let, but transparently wraps all bindings with delay.

Examples:

(macroexpand-1 '(letd [a 1] a)) => (let [a (delay 1)] @a)

(letd [a (do (println "a evaluated") 1) {:keys [b]} (do (println "b evaluated") {:b 2}) [_ _ c] (do (println "c evaluated") [1 2 3])] (if (even? b) a c)) => (out) b evaluated (out) a evaluated 1

Like let, but transparently wraps all bindings with delay.

Examples:

(macroexpand-1 '(letd [a 1]
                  a))
=> (let [a (delay 1)]
     @a)

(letd [a (do (println "a evaluated")
             1)
       {:keys [b]} (do (println "b evaluated")
                       {:b 2})
       [_ _ c] (do (println "c evaluated")
                   [1 2 3])]
  (if (even? b)
    a
    c))
=>
(out) b evaluated
(out) a evaluated
1
raw docstring

lookupclj

(lookup db k v)

Returns the first document found with the given key and value.

For example: (lookup db :user/email "hello@example.com") => {:xt/id #uuid "...", :user/email "hello@example.com"}

Returns the first document found with the given key and value.

For example:
(lookup db :user/email "hello@example.com")
=> {:xt/id #uuid "...", :user/email "hello@example.com"}
raw docstring

lookup-idclj

(lookup-id db k v)

Returns the ID of the first document found with the given key and value.

For example: (lookup db :user/email "hello@example.com") => #uuid "..."

Returns the ID of the first document found with the given key and value.

For example:
(lookup db :user/email "hello@example.com")
=> #uuid "..."
raw docstring

mailersendclj

(mailersend {:keys [mailersend/api-key mailersend/defaults] :as sys} opts)

Sends an email with MailerSend.

See https://developers.mailersend.com/api/v1/email.html#send-an-email. Does a POST request on the /v1/email endpoint and returns the X-Message-Id response header on success. On failure, prints an error message and returns false.

opts is a map which will be converted to JSON and included as the body of the request. defaults is a map from paths to default values. It will be combined with opts. For example:

(mailersend {:mailersend/api-key "..." :mailersend/defaults {[:from :email] "hello@mail.example.com" [:from :name] "My Application" [:reply_to :email] "hello@example.com" [:reply_to :name] "My Application"}} {:to [{:email "recipient@example.com"}] :subject "Some subject" :text "Some text" :from {:name "This will override the default value of 'My Application'"}})

Sends an email with MailerSend.

See https://developers.mailersend.com/api/v1/email.html#send-an-email. Does a
POST request on the /v1/email endpoint and returns the X-Message-Id response
header on success. On failure, prints an error message and returns false.

opts is a map which will be converted to JSON and included as the body of the
request. defaults is a map from paths to default values. It will be combined
with opts. For example:

(mailersend {:mailersend/api-key "..."
             :mailersend/defaults {[:from :email] "hello@mail.example.com"
                                   [:from :name] "My Application"
                                   [:reply_to :email] "hello@example.com"
                                   [:reply_to :name] "My Application"}}
            {:to [{:email "recipient@example.com"}]
             :subject "Some subject"
             :text "Some text"
             :from {:name "This will override the default value of 'My Application'"}})
raw docstring

nbspclj

A Rum data structure for a non-breaking space.

A Rum data structure for a non-breaking space.
raw docstring

normalize-emailclj

(normalize-email email)

Normalizes an email address to make future lookups easier.

Trims leading and trailing whitespace and converts to lower case. Returns nil if the email is empty after trimming.

Normalizes an email address to make future lookups easier.

Trims leading and trailing whitespace and converts to lower case. Returns nil
if the email is empty after trimming.
raw docstring

nowclj

(now)

Same as (java.util.Date.)

Same as (java.util.Date.)
raw docstring

parse-dateclj

(parse-date date & [format])

Parses date (a string) using java.text.SimpleDateFormat.

If format isn't provided, uses rfc3339.

Parses date (a string) using java.text.SimpleDateFormat.

If format isn't provided, uses rfc3339.
raw docstring

pprintclj

(pprint & args)

Alias of clojure.pprint/pprint

Alias of clojure.pprint/pprint
raw docstring

qclj

(q db query & args)

Convenience wrapper for xtdb.api/q.

If the :find value is not a vector, results will be passed through (map first ...). Also throws an exception if (count args) doesn't match (count (:in query)).

Convenience wrapper for xtdb.api/q.

If the :find value is not a vector, results will be passed through
(map first ...). Also throws an exception if (count args) doesn't match
(count (:in query)).
raw docstring

refreshclj

(refresh)

Stops the system, refreshes source files, and restarts the system.

The system is stopped by calling all the functions in (:biff/stop @com.biffweb/system). (:biff/after-refresh @system) is a fully-qualified symbol which will be resolved and called after refreshing. See https://biffweb.com/docs/#system-composition

Stops the system, refreshes source files, and restarts the system.

The system is stopped by calling all the functions in (:biff/stop
@com.biffweb/system). (:biff/after-refresh @system) is a fully-qualified
symbol which will be resolved and called after refreshing. See
https://biffweb.com/docs/#system-composition
raw docstring

reitit-handlerclj

(reitit-handler {:keys [router routes on-error] :as opts})

Convenience wrapper for reitit.ring/ring-handler.

Only one of router or routes needs to be given. If you pass in routes, it will be wrapped with (reitit.ring/router routes). on-error is an optional Ring handler. The request map passed to it will include a :status key (either 404, 405, or 406).

Includes reitit.ring/redirect-trailing-slash-handler.

Convenience wrapper for reitit.ring/ring-handler.

Only one of router or routes needs to be given. If you pass in routes, it
will be wrapped with (reitit.ring/router routes). on-error is an optional
Ring handler. The request map passed to it will include a :status key (either
404, 405, or 406).

Includes reitit.ring/redirect-trailing-slash-handler.
raw docstring

renderclj

(render body)

Renders body with rum/render-static-markup and returns a 200 response.

Renders body with rum/render-static-markup and returns a 200 response.
raw docstring

rfc3339clj

Same as "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", for use with parse-date and format-date.

Same as "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", for use with parse-date and format-date.
raw docstring

safe-mergeclj

(safe-merge & ms)

Like merge, but throws an exception if any maps share keys.

Like merge, but throws an exception if any maps share keys.
raw docstring

select-ns-asclj

(select-ns-as m ns-from ns-to)

Selects and renames keys from m based on the namespace.

Examples:

(select-ns-as {:foo/a 1, :foo.bar/b 2, :baz/c 3} 'foo 'quux) => {:quux/a 1, :quux.bar/b 2}

(select-ns-as {:foo/a 1, :foo.bar/b 2, :baz/c 3} 'foo nil) => {:a 1, :bar/b 2}

Selects and renames keys from m based on the namespace.

Examples:

(select-ns-as {:foo/a 1, :foo.bar/b 2, :baz/c 3} 'foo 'quux)
=> {:quux/a 1, :quux.bar/b 2}

(select-ns-as {:foo/a 1, :foo.bar/b 2, :baz/c 3} 'foo nil)
=> {:a 1, :bar/b 2}
raw docstring

shclj

(sh & args)

Runs a shell command.

Returns the output if successful; otherwise, throws an exception.

Runs a shell command.

Returns the output if successful; otherwise, throws an exception.
raw docstring

sha256clj

(sha256 string)

Returns the SHA256 hash of string.

Returns the SHA256 hash of string.
raw docstring

start-nodeclj

(start-node {:keys [topology dir opts jdbc-spec pool-opts kv-store]
             :or {kv-store :rocksdb}
             :as options})

A higher-level version of xtdb.api/start-node.

Calls xtdb.api/sync before returning the node.

topology: One of #{:standalone :jdbc}. kv-store: One of #{:rocksdb :lmdb}. Default :rocksdb dir: A path to store RocksDB instances in. jdbc-spec, pool-opts: Used only when topology is :jdbc. Passed in as {:xtdb.jdbc/connection-pool {:db-spec jdbc-spec :pool-opts pool-opts ...}}. opts: Additional options to pass to xtdb.api/start-node.

A higher-level version of xtdb.api/start-node.

Calls xtdb.api/sync before returning the node.

topology:   One of #{:standalone :jdbc}.
kv-store:   One of #{:rocksdb :lmdb}. Default :rocksdb
dir:        A path to store RocksDB instances in.
jdbc-spec,
pool-opts:  Used only when topology is :jdbc. Passed in as
            {:xtdb.jdbc/connection-pool
             {:db-spec jdbc-spec :pool-opts pool-opts ...}}.
opts:       Additional options to pass to xtdb.api/start-node.
raw docstring

start-systemclj

(start-system init)

Starts a system from an initial system map.

Stores the system in the com.biffweb/system atom. See https://biffweb.com/docs/#system-composition

Starts a system from an initial system map.

Stores the system in the com.biffweb/system atom. See
https://biffweb.com/docs/#system-composition
raw docstring

submit-txclj

(submit-tx {:keys [biff.xtdb/node] :as sys} biff-tx)

High-level wrapper over xtdb.api/submit-tx.

See https://biffweb.com/docs/#transactions.

High-level wrapper over xtdb.api/submit-tx.

See https://biffweb.com/docs/#transactions.
raw docstring

systemclj


unsafeclj

(unsafe html)

Returns {:dangerouslySetInnerHTML {:__html html}}, for use with Rum.

Returns {:dangerouslySetInnerHTML {:__html html}}, for use with Rum.
raw docstring

use-chimeclj

(use-chime {:biff.chime/keys [tasks] :as sys})

A Biff component for running scheduled tasks with Chime.

See https://github.com/jarohen/chime. tasks is a collection of maps, for example:

[{:task (fn [system] (println "hello there")) :schedule (iterate #(biff/add-seconds % 60) (java.util.Date.))}]

This value of tasks would print "hello there" every 60 seconds. task is a single-argument function that receives the system map. schedule is a zero-argument function that returns a (possibly infinite) sequence of times at which to run the task function.

A Biff component for running scheduled tasks with Chime.

See https://github.com/jarohen/chime. tasks is a collection of maps, for
example:

[{:task (fn [system] (println "hello there"))
  :schedule (iterate #(biff/add-seconds % 60) (java.util.Date.))}]

This value of tasks would print "hello there" every 60 seconds. task is a
single-argument function that receives the system map. schedule is a
zero-argument function that returns a (possibly infinite) sequence of times
at which to run the task function.
raw docstring

use-configclj

(use-config sys)

Reads config from (:biff/config sys), and edn file, and merges into sys.

The config file's contents should be a map from environments to config keys and values, for example:

{:prod {:host "example.com" :port 8080} :dev {:merge [:prod] :host "localhost"}}

The current environment should be stored in the BIFF_ENV environment variable. The default value is prod. To inherit config from other environments, set :merge to a sequence of environment keys.

Reads config from (:biff/config sys), and edn file, and merges into sys.

The config file's contents should be a map from environments to config keys
and values, for example:

{:prod {:host "example.com"
        :port 8080}
 :dev {:merge [:prod]
       :host "localhost"}}

The current environment should be stored in the BIFF_ENV environment variable.
The default value is `prod`. To inherit config from other environments, set
:merge to a sequence of environment keys.
raw docstring

use-hawkclj

(use-hawk {:biff.hawk/keys [on-save exts paths]
           :or {paths ["src" "resources"]}
           :as sys})

A Biff component that runs code when files are changed, via Hawk.

See (https://github.com/wkf/hawk).

on-save: A single-argument function to call whenever a file is saved. Receives the system map as a parameter. The function is called no more than once every 500 milliseconds. paths: A collection of root directories to monitor for file changes. exts: If exts is non-empty, files that don't end in one of the extensions will be ignored.

A Biff component that runs code when files are changed, via Hawk.

See (https://github.com/wkf/hawk).

on-save:  A single-argument function to call whenever a file is saved.
          Receives the system map as a parameter. The function is called no
          more than once every 500 milliseconds.
paths:    A collection of root directories to monitor for file changes.
exts:     If exts is non-empty, files that don't end in one of the extensions
          will be ignored.
raw docstring

use-jettyclj

(use-jetty
  {:biff/keys [host port handler] :or {host "localhost" port 8080} :as sys})

A Biff component that starts a Jetty web server.

A Biff component that starts a Jetty web server.
raw docstring

use-outer-default-middlewareclj

(use-outer-default-middleware sys)

A Biff component that wraps :biff/handler with middleware that depends on the system map.

Includes wrap-ring-defaults and wrap-env.

A Biff component that wraps :biff/handler with middleware that depends on the system map.

Includes wrap-ring-defaults and wrap-env.
raw docstring

use-random-default-secretsclj

(use-random-default-secrets sys)

A Biff component that merges temporary secrets into the system map if needed.

Sets :biff.middleware/cookie-secret and :biff/jwt-secret if they are nil. The secrets will not persist if the system is restarted. Can be useful in development. e.g. a config.edn.TEMPLATE can be checked into a project's repository without secrets set. Contributers can run the project by copying the file to config.edn, without needing to modify it.

This component should not be relied upon in production; instead you should save secrets in config.edn. This is done automatically at project setup time for new Biff projects.

A Biff component that merges temporary secrets into the system map if needed.

Sets :biff.middleware/cookie-secret and :biff/jwt-secret if they are nil. The
secrets will not persist if the system is restarted. Can be useful in
development. e.g. a config.edn.TEMPLATE can be checked into a project's
repository without secrets set. Contributers can run the project by copying
the file to config.edn, without needing to modify it.

This component should not be relied upon in production; instead you should
save secrets in config.edn. This is done automatically at project setup time
for new Biff projects.
raw docstring

use-tx-listenerclj

(use-tx-listener {:keys [biff.xtdb/on-tx biff.xtdb/node] :as sys})

If on-tx is provided, starts an XTDB transaction listener.

Calls on-tx whenever a new transaction is successfully indexed. on-tx receives the system map and the transaction, i.e. (on-tx system tx). tx is the transaction as returned by (xtdb.api/open-tx-log node tx-id true). on-tx will not be called concurrently: if a second transaction is indexed while on-tx is still running, use-tx-listener will wait until it finishes.

If on-tx is provided, starts an XTDB transaction listener.

Calls on-tx whenever a new transaction is successfully indexed. on-tx
receives the system map and the transaction, i.e. (on-tx system tx). tx is
the transaction as returned by (xtdb.api/open-tx-log node tx-id true). on-tx
will not be called concurrently: if a second transaction is indexed while
on-tx is still running, use-tx-listener will wait until it finishes.
raw docstring

use-whenclj

(use-when f & components)

Passes the system map to components only if (f system) is true.

See https://biffweb.com/docs/#system-composition

Passes the system map to components only if (f system) is true.

See https://biffweb.com/docs/#system-composition
raw docstring

use-xtclj

(use-xt {:biff.xtdb/keys [topology kv-store dir opts] :as sys})

A Biff component that starts an XTDB node.

Sets :biff.xtdb/node on the system map. topology, kv-store, dir and opts are passed to start-node. Any keys matching :biff.xtdb.jdbc/* or :biff.xtdb.jdbc-pool/* are passed in as jdbc-spec and pool-opts, respectively.

A Biff component that starts an XTDB node.

Sets :biff.xtdb/node on the system map. topology, kv-store, dir and opts are
passed to start-node. Any keys matching :biff.xtdb.jdbc/* or
:biff.xtdb.jdbc-pool/* are passed in as jdbc-spec and pool-opts,
respectively.
raw docstring

wrap-anti-forgery-websocketsclj

(wrap-anti-forgery-websockets handler)

Ensure that websocket upgrade requests pass a CSRF check.

If the client requests a websocket upgrade, the Origin header must be the same as the :biff/base-url key in the request map. Otherwise a 403 response is given.

Ensure that websocket upgrade requests pass a CSRF check.

If the client requests a websocket upgrade, the Origin header must be the
same as the :biff/base-url key in the request map. Otherwise a 403
response is given.
raw docstring

wrap-envclj

(wrap-env handler system)

Merges the system map with incoming requests and sets :biff/db.

See assoc-db.

Merges the system map with incoming requests and sets :biff/db.

See assoc-db.
raw docstring

wrap-index-filesclj

(wrap-index-files
  handler
  {:keys [index-files] :or {index-files ["index.html"]} :as opts})

If handler returns nil, try again with each index file appended to the URI in turn.

If handler returns nil, try again with each index file appended to the URI in turn.
raw docstring

wrap-inner-defaultsclj

(wrap-inner-defaults handler opts)

Wraps handler with various middleware which don't depend on the system map.

Includes wrap-log-requests, wrap-internal-error, wrap-resource, and Muuntaja's wrap-params and wrap-format (see https://github.com/metosin/muuntaja). opts is passed to wrap-resource and wrap-internal-error.

This function can wrap a Ring handler outside of a call to biff/start-system, For example:

(def handler (wrap-inner-defaults ... {}))

(defn start [] (biff/start-system {:biff/handler #'handler ...}))

This way, handler and its middleware can be redefined from the repl without needing to restart the system.

Wraps handler with various middleware which don't depend on the system map.

Includes wrap-log-requests, wrap-internal-error, wrap-resource, and
Muuntaja's wrap-params and wrap-format (see https://github.com/metosin/muuntaja).
opts is passed to wrap-resource and wrap-internal-error.

This function can wrap a Ring handler outside of a call to biff/start-system,
For example:

(def handler (wrap-inner-defaults ... {}))

(defn start []
  (biff/start-system
    {:biff/handler #'handler
     ...}))

This way, handler and its middleware can be redefined from the repl without
needing to restart the system.
raw docstring

wrap-internal-errorclj

(wrap-internal-error handler {:biff.middleware/keys [on-error]})

Catches exceptions from handler, prints a stack trace, and returns a 500 response.

You may optionally provide on-error, a single-argument function that receives the request map with the :status key set to 500. The default implementation returns a plain Internal Server Error message.

Catches exceptions from handler, prints a stack trace, and returns a 500 response.

You may optionally provide on-error, a single-argument function that receives
the request map with the :status key set to 500. The default implementation
returns a plain Internal Server Error message.
raw docstring

wrap-log-requestsclj

(wrap-log-requests handler)

Prints execution time, status, request method, uri and query params for each request.

Prints execution time, status, request method, uri and query params for each request.
raw docstring

wrap-render-rumclj

(wrap-render-rum handler)

If handler returns a vector, pass it to rum.core/render-static-markup and return a 200 response.

If handler returns a vector, pass it to rum.core/render-static-markup and return a 200 response.
raw docstring

wrap-resourceclj

(wrap-resource handler
               {:biff.middleware/keys [root index-files]
                :or {root "public" index-files ["index.html"]}
                :as opts})

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.

Checks for a static resource first. If none is found, passes the request to handler.

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.

Checks for a static resource first. If none is found, passes the request to
handler.
raw docstring

wrap-ring-defaultsclj

(wrap-ring-defaults handler
                    {:biff.middleware/keys [session-store cookie-secret secure
                                            session-max-age]
                     :or {session-max-age (* 60 60 24 60) secure true}
                     :as opts})

Wraps handler with ring.middleware.defaults/wrap-defaults.

secure: if true, uses ring.middleware.defaults/secure-site-defaults, else uses site-defaults. cookie-secret: if provided, session-store is set with ring.middleware.session.cookie/cookie-store session-store: passed to wrap-defaults under the [:session :store] path. sesion-max-age: the number of seconds after which a session should expire.

Disables CSRF checks. You must wrap non-API routes with ring.middleware.anti-forgery. The Biff project template does this by default. Disables SSL redirects under the assumption that this is handled by e.g. NGINX. Also sets SameSite=Lax explicitly on the session cookie.

Wraps handler with ring.middleware.defaults/wrap-defaults.

secure:          if true, uses ring.middleware.defaults/secure-site-defaults,
                 else uses site-defaults.
cookie-secret:   if provided, session-store is set with
                 ring.middleware.session.cookie/cookie-store
session-store:   passed to wrap-defaults under the [:session :store] path.
sesion-max-age:  the number of seconds after which a session should expire.

Disables CSRF checks. You must wrap non-API routes with
ring.middleware.anti-forgery. The Biff project template does this by default.
Disables SSL redirects under the assumption that this is handled by e.g.
NGINX. Also sets SameSite=Lax explicitly on the session cookie.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close