Skip to main content

Module groups

Module groups 

Source
Expand description

The middleware groups Rainier ships — Laravel’s 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. Finding out what 'web' means in Laravel means grepping the kernel.

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. Laravel’s $middlewareGroups['web'] = [...] 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.