Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register a route middleware #1247

Closed
0x1793d1 opened this issue Jan 2, 2020 · 3 comments
Closed

Register a route middleware #1247

0x1793d1 opened this issue Jan 2, 2020 · 3 comments
Labels
A-web project: actix-web C-feature Category: new functionality

Comments

@0x1793d1
Copy link
Contributor

0x1793d1 commented Jan 2, 2020

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!

@fafhrd91
Copy link
Member

fafhrd91 commented Jan 2, 2020

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

@fafhrd91 fafhrd91 closed this as completed Jan 2, 2020
@ppoliani
Copy link

Is there any particular reason why this is implemented? I believe that this is quite a common thing to have in a web framework.

@robjtede
Copy link
Member

Planned for 4.1. See #2725

@robjtede robjtede added this to the actix-web v4.1 milestone Apr 27, 2022
@robjtede robjtede added A-web project: actix-web C-feature Category: new functionality labels Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web C-feature Category: new functionality
Projects
None yet
Development

No branches or pull requests

4 participants