You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a service to do some custom routing that isn't supported by axum::Router. When I add it to a root-level router, it works fine. However, when I add it to a router and then nest that router, it doesn't ever seem to be called.
// This seems to worklet 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);
Darwin Bryans-MacBook-Pro.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64 x86_64
Crates
axum
Description
As mentioned above, it seems like when calling Router::nest with another Router as the target, my custom layer gets lost.
However, if I turn my custom layer into a service without using another Router and nest that, it seems to work fine (but then I lose the ability to do other additional routing).
Summary:
🥰 Custom layer at root level
🥰 Custom layer when turned into its own service and nested
🤬 Custom layer added to another Router, then nested in root Router
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() using ServiceExt::boxed_clone.
Bug Report
I created a service to do some custom routing that isn't supported by
axum::Router
. When I add it to a root-level router, it works fine. However, when I add it to a router and then nest that router, it doesn't ever seem to be called.Version
Platform
Crates
Description
As mentioned above, it seems like when calling
Router::nest
with anotherRouter
as the target, my custom layer gets lost.However, if I turn my custom layer into a service without using another
Router
and nest that, it seems to work fine (but then I lose the ability to do other additional routing).Summary:
Reproduction is here: https://github.com/bryanburgers/axum-nest-repro.
To try it out, you can do
cargo run
in one terminal to start the server on0.0.0.0:3000
andcargo test
in another terminal.Ultimately, the code that I would like to work looks like this
but once I try to nest
odata_router
instead of putting.layer(odata_layer)
on the root, I can no longer get theodata_layer
to handle requests.The text was updated successfully, but these errors were encountered: