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 apiwith an explicit per-minute limit.- normalise_
input - Normalise input — trim strings, and turn
""intonull. - 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.