Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions crates/cli/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,15 @@ pub fn build_router(
}
}

if let Some(prefix) = prefix {
let path = format!("{}/", prefix.trim_end_matches('/'));
router = Router::new().nest(&path, router);
// We normalize the prefix:
// - if it's None, it becomes '/'
// - if it's Some(..), any trailing '/' is first trimmed, then a '/' is added
let prefix = format!("{}/", prefix.unwrap_or_default().trim_end_matches('/'));
// Then we only nest the router if the prefix is not empty and not the root
// If we blindly nest the router if the prefix is Some("/"), axum will panic as
// we're not supposed to nest the router at the root
if !prefix.is_empty() && prefix != "/" {
router = Router::new().nest(&prefix, router);
}

router = router.fallback(mas_handlers::fallback);
Expand Down
Loading