middleware did not take effect
In the following example, the auth middleware did not take effect. It will run create_library directly without identity verification.
web::resource("/library")
.route(web::get().to(library_handlers::get_libraries))
.route(web::post().wrap(auth.clone()).to(library_handlers::create_library)),
Your Environment
- Rust Version: 1.89.0
- Actix Web Version: 4.11.0
I don't think you can use wrap on route level, it should be either on app or scope/resource level:
App::new().service(
web::scope("/library")
.route("", web::get().to(library_handlers::get_libraries))
.service(
web::resource("")
.wrap(auth.clone())
.route(web::post().to(library_handlers::create_library)),
),
)
You are correct. However, my example can compile successfully, which is indeed misleading.
@Yancey2023 am interested in working on this issue
Worth mentioning we do have a relevant test: https://github.com/actix/actix-web/blob/f4ee39cdd707ab4973ec4fe8650e6c78d09f6008/actix-web/src/route.rs#L359-L395
The only difference to OP's code sample is the ordering of .wrap and .to.