Different middleware for different groups #292
-
Is this valid code? The documentation just creates one group. What about multiple/different groups and combination with groups without layer. |
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Aug 31, 2021
Replies: 1 comment 4 replies
-
While it is valid it probably doesn't do what you want. You can do something like this instead: let foo = Router::new()
.route("/", get(root))
.route("/some", get(some))
.layer(auth);
let bar = Router::new()
.route("/", post(root))
.layer(auth)
.layer(db);
let baz = Router::new()
.route("/login", post(login));
let app = foo.or(bar).or(baz); |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
cemoktra
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While it is valid it probably doesn't do what you want.
layer
applies to all routes above it, meaningauth
is applied twice to the first two routes.You can do something like this instead: