Fix basename handling in router (#2297)

This commit is contained in:
Muhammad Hamza 2021-12-27 00:38:05 +05:00 committed by GitHub
parent 61efc8042e
commit 5181e1aca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,4 @@
use std::borrow::Cow;
use crate::utils::{base_url, strip_slash_suffix};
use crate::utils::strip_slash_suffix;
use crate::Routable;
// re-export Router because the macro needs to access it
@ -8,16 +6,9 @@ pub type Router = route_recognizer::Router<String>;
/// Build a `route_recognizer::Router` from a `Routable` type.
pub fn build_router<R: Routable>() -> Router {
let base = base_url();
let mut router = Router::new();
R::routes().iter().for_each(|path| {
let route = match base {
Some(ref base) => Cow::from(format!("{}{}", base, path)),
None => (*path).into(),
};
let stripped_route = strip_slash_suffix(&route);
let stripped_route = strip_slash_suffix(path);
router.add(stripped_route, path.to_string());
});