Custom layers on *nested* router isn't getting called #1246
-
Bug ReportI created a service to do some custom routing that isn't supported by // This seems to work
let my_custom_router = ...;
let app = Router::new().layer(my_custom_router); // This compiles, but my custom router never gets calls to `Service::call`
let my_custom_router = ...;
let nested = Router::new().layer(my_custom_router);
let app = Router::new().nest("/nested", nested); Version
Platform
Crates
DescriptionAs mentioned above, it seems like when calling However, if I turn my custom layer into a service without using another Summary:
Reproduction is here: https://github.com/bryanburgers/axum-nest-repro. To try it out, you can do Ultimately, the code that I would like to work looks like this pub fn create_app(context: Context) -> Router {
let odata_layer = odata_router::Router::new()
.get("Property", get_property) // GET /odata/Property('12345')
.list("Property", list_property); // GET /odata/Property?$query=...
let odata_router = Router::new().layer(odata_layer);
let api_router = Router::new()
.route("/properties", get(list_own_properties).post(post_new_property))
.route("/properties/:id", get(get_own_property).patch(patch_own_property))
.route("/properties/:id/validate", post(validate_own_property));
Router::new()
.nest("/api", api_router)
.nest("/odata", odata_router)
.layer(Extension(context)) but once I try to nest |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A workaround is to box the nested service |
Beta Was this translation helpful? Give feedback.
Router::new().layer(odata_layer);
only adds the layer to the fallback which is then discarded when you nest the router. Axum 0.5 doesn't support nested fallbacks.A workaround is to box the nested service
Router::new().layer(odata_layer).boxed_clone()
usingServiceExt::boxed_clone
.