sigildocs

(sigil web middleware)

(sigil web middleware) - Composable Middleware

Provides middleware composition for request/response processing. Middleware wraps handlers to add cross-cutting concerns like logging, authentication, CORS, etc.

Two styles are supported:

  1. Factory style (traditional): (wrap-middleware handler (logger-middleware) (cors-middleware '("*")))
  2. Chain style (with chain/-> macro): (chain handler (with-logging) (with-cors "*") (with-not-found))

Exports

Wrap a handler with multiple middleware Middleware are applied right-to-left (last middleware is outermost) Each middleware is: (handler) -> new-handler

Compose multiple middleware into one Returns a single middleware function

Log requests and responses Options:

  • output: port to write to (default: current-output-port)

Get current time in milliseconds

Add CORS headers to responses origins: list of allowed origins, or '("*") for any

Set default Content-Type if not present

Return 404 response if handler returns #f

with-loggingvariable

Wrap handler with request/response logging Keywords: output: - port for log output (default: current-output-port)

with-corsvariable

Wrap handler with CORS headers Keywords: allow-origin: - allowed origin ("" for any, default: "") allow-methods: - allowed methods string allow-headers: - allowed headers string

Wrap handler with default Content-Type Keywords: default: - default content type (default: "text/html")

Wrap handler with 404 fallback Keywords: body: - custom 404 body HTML