Scoping
Middlewares apply to all routes that were registered after them.
src/order1/blueprint.rs
use pavex::blueprint::router::GET;
use pavex::blueprint::Blueprint;
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::wrap1));
bp.route(GET, "/", f!(super::handler));
bp.wrap(f!(crate::wrap2));
bp
}
The request handler for GET /
has been registered before wrap2
, so it is not affected by it.
Nesting
The same principle applies to nested Blueprint
s.
Middlewares apply to all routes in nested Blueprint
s that were nested after the middleware.
src/order2/blueprint.rs
use pavex::blueprint::router::GET;
use pavex::blueprint::Blueprint;
use pavex::f;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(f!(crate::wrap1));
bp.nest(nested());
bp.wrap(f!(crate::wrap2));
bp
}
pub fn nested() -> Blueprint {
let mut bp = Blueprint::new();
bp.route(GET, "/", f!(super::handler));
bp
}
The wrap2
middleware has been registered after the call to .nest
,
so it won't apply to the route registered against the nested Blueprint
, GET /
.