(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:
- Factory style (traditional): (wrap-middleware handler (logger-middleware) (cors-middleware '("*")))
- Chain style (with chain/-> macro): (chain handler (with-logging) (with-cors "*") (with-not-found))
Exports
wrap-middlewareprocedureWrap a handler with multiple middleware Middleware are applied right-to-left (last middleware is outermost) Each middleware is: (handler) -> new-handler
compose-middlewareprocedureCompose multiple middleware into one Returns a single middleware function
logger-middlewareprocedureLog requests and responses Options:
- output: port to write to (default: current-output-port)
current-time-msprocedureGet current time in milliseconds
cors-middlewareprocedureAdd CORS headers to responses origins: list of allowed origins, or '("*") for any
content-type-middlewareprocedureSet default Content-Type if not present
not-found-middlewareprocedureReturn 404 response if handler returns #f
with-loggingvariableWrap handler with request/response logging Keywords: output: - port for log output (default: current-output-port)
with-corsvariableWrap handler with CORS headers Keywords: allow-origin: - allowed origin ("" for any, default: "") allow-methods: - allowed methods string allow-headers: - allowed headers string
with-content-typevariableWrap handler with default Content-Type Keywords: default: - default content type (default: "text/html")
with-not-foundvariableWrap handler with 404 fallback Keywords: body: - custom 404 body HTML