Scoping
Middlewares apply to all routes that were registered after them.
// [...]
use pavex::Blueprint;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(WRAP_1);
bp.route(GET_INDEX);
bp.wrap(WRAP_2);
// [...]
}
The request handler for GET / has been registered before WRAP_2, so it is not affected by it.
Nesting
The same principle applies to nested Blueprints.
Middlewares apply to all routes in nested Blueprints that were nested after the middleware.
// [...]
use pavex::Blueprint;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.wrap(WRAP_1);
bp.nest(nested());
bp.wrap(WRAP_2);
// [...]
}
pub fn nested() -> Blueprint {
let mut bp = Blueprint::new();
bp.route(GET_INDEX);
// [...]
}
The WRAP_2 middleware has been registered after the call to .nest,
so it won't apply to the route registered against the nested Blueprint, GET /.