Actix-web: Register a route middleware

Created on 2 Jan 2020  路  1Comment  路  Source: actix/actix-web

Hi,

Is there a way to register a middleware on route level?
I created an Authenticate middleware to do a redirection if no user is logged in and I'd like to register the middleware only on delete method.

The problem is that I only can do it on resource level like below:

.service(
    web::resource("/{repository}/{architecture}/{name}")
        .wrap(Authenticate::new("/user/sign_in"))
        .route(web::get().to(controller::package::get_package))
        .route(web::delete().to(controller::package::delete_package)),
)

Thanks!

>All comments

You can not register Middlewares on route level. And it is not planned

Was this page helpful?
0 / 5 - 0 ratings