-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
axum 0.6 version Router::new().nest() #1677
Comments
Thats an intentional change in 0.6. You can use |
I try let app = Router::new().nest("/api", routers().merge(white_routers()));
fn routers()->Router{
Router::new().nest("/sys", sys())
}
fn white_routers()->Router{
Router::new().nest("/sys", white_sys())
}
pub fn sys()->Router{
Router::new().route("/setting", ...).route("/user", ...)
}
pub fn white_sys()->Router{
Router::new().route("/white", ...)
} |
@chenlunfu You still have the same issue there, you are trying to nest let app = Router::new().nest("/api", api_routers());
fn api_routers()->Router{
Router::new().nest("/sys", sys().merge(white_sys())
}
pub fn sys()->Router{
Router::new().route("/setting", ...).route("/user", ...)
}
pub fn white_sys()->Router{
Router::new().route("/white", ...)
} Also I've reformatted your comments a little bit. Please use markdown formatting to make your posts / comments more readable. |
Thank you for your help,But I have two layers because I want to add permissions in one layer,white_routers() no permission required
|
That is no problem, you can do |
No, There's a problem.such as, |
Well, you will have to apply the layer in multiple places, or use less nesting (currently, there is a performance regression with nesting anyways). I would likely do something like let app = Router::new().nest("/api", api_routes());
fn api_routes() -> Router {
authenticated_routes().merge(public_routes())
}
fn authenticated_routes() -> Router {
Router::new()
.route("/sys/setting", ...)
.route("/sys/user", ...)
.route("/store/setting", ...)
.route("/store/user", ...)
.layer(auth_layer)
}
fn public_routes() -> Router {
Router::new()
.route("/sys/white", ...)
.route("/store/white", ...)
} |
Thank you for your help,but axum 0.5 work normally,Will later versions support it? |
You should expect breaking changes when updating from 0.5 to 0.6. Just because something worked on 0.5 doesn't guarantee that it'll work on 0.6 but of course we don't break stuff without a good reason.
Perhaps but its not clear yet. There are some tradeoffs to consider. Its also related to #1624 which I haven't had time to look into yet. |
Thank you for your help,But i still think this is a bug. I will try to fix it |
Bug Report
Version
axum 0.6
Platform
PC
Crates
Description
axum 0.5 work normally,but axum 0.6 work panick
The text was updated successfully, but these errors were encountered: