Skip to main content

Module groups

Module groups 

Source
Expand description

The middleware groups Rainier ships — web and api, as functions rather than as keys in a map.

ⓘ
use rainier_framework::groups;

router.group(GroupAttributes::new().middleware(groups::web()), |router| {
    router.get("/", home);
});

Three things follow from a group being a function.

You can find it. “Go to definition” on groups::web() lands on the list. A string key would send you grepping the kernel instead.

You cannot misspell it. groups::wev() does not compile. 'wev' boots fine and serves every page in that group with no session and no security headers.

Overriding is composition, not replacement. Reassigning a 'web' key in a middleware map replaces the whole list, which is how people accidentally drop StartSession while adding one thing. Here an application writes its own function and says what it is starting from:

ⓘ
pub fn web() -> MiddlewareStack {
    rainier_framework::groups::web().with(RequestId::new())
}

Functions§

api
CORS plus a rate limit — what a JSON API wants.
api_throttled
api with an explicit per-minute limit.
normalise_input
Normalise input — trim strings, and turn "" into null.
session
Start a session, using whichever store the application bound.
trust_local_proxies
Trust X-Forwarded-* from the loopback and the private ranges.
web
Security headers plus a session — what a browser-facing page wants.