glimr/http/middleware/serve_static

Serve Static Middleware

Each middleware lives in its own module so the kernel pipeline can compose them independently — apps that don’t serve static files can simply omit this step. Pulling the directory prefix from app config rather than hardcoding it means the URL path and filesystem path stay in sync without duplicating the value across middleware and config.

Values

pub fn run(
  ctx: context.Context(app),
  next: fn(context.Context(app)) -> response.Response(wisp.Body),
) -> response.Response(wisp.Body)

The config is loaded via persistent_term so checking the static prefix on every request adds almost no overhead. Matching static files early means asset requests skip session parsing, CSRF validation, and other downstream middleware that only applies to dynamic routes.

Search Document