File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -238,9 +238,15 @@ pub fn build_router(
238
238
}
239
239
}
240
240
241
- if let Some ( prefix) = prefix {
242
- let path = format ! ( "{}/" , prefix. trim_end_matches( '/' ) ) ;
243
- router = Router :: new ( ) . nest ( & path, router) ;
241
+ // We normalize the prefix:
242
+ // - if it's None, it becomes '/'
243
+ // - if it's Some(..), any trailing '/' is first trimmed, then a '/' is added
244
+ let prefix = format ! ( "{}/" , prefix. unwrap_or_default( ) . trim_end_matches( '/' ) ) ;
245
+ // Then we only nest the router if the prefix is not empty and not the root
246
+ // If we blindly nest the router if the prefix is Some("/"), axum will panic as
247
+ // we're not supposed to nest the router at the root
248
+ if !prefix. is_empty ( ) && prefix != "/" {
249
+ router = Router :: new ( ) . nest ( & prefix, router) ;
244
250
}
245
251
246
252
router = router. fallback ( mas_handlers:: fallback) ;
You can’t perform that action at this time.
0 commit comments