From 7f9768ade4eb7886f55d8c3384785ec51ac69961 Mon Sep 17 00:00:00 2001 From: VishnuSanal Date: Tue, 14 May 2024 12:14:16 +0530 Subject: [PATCH] fixes #818 --- src/server.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/server.rs b/src/server.rs index 28f49ec25..ee7837489 100644 --- a/src/server.rs +++ b/src/server.rs @@ -280,6 +280,24 @@ impl Server { function: FunctionInfo, is_const: bool, ) { + + self.save_route(py, route_type, route, &function, is_const); + + if &route[route.len() - 1..] == "/" { + self.save_route(py, route_type, &route[0..route.len() - 1], &function, is_const); + } else { + self.save_route(py, route_type, &format!("{}/", route), &function, is_const); + } + } + + pub fn save_route( + &self, + py: Python, + route_type: &HttpMethod, + route: &str, + function: &FunctionInfo, + is_const: bool, + ) { debug!("Route added for {:?} {} ", route_type, route); let asyncio = py.import("asyncio").unwrap(); let event_loop = asyncio.call_method0("get_event_loop").unwrap(); @@ -287,7 +305,7 @@ impl Server { if is_const { match self .const_router - .add_route(route_type, route, function, Some(event_loop)) + .add_route(route_type, route, function.clone(), Some(event_loop)) { Ok(_) => (), Err(e) => { @@ -295,7 +313,7 @@ impl Server { } } } else { - match self.router.add_route(route_type, route, function, None) { + match self.router.add_route(route_type, route, function.clone(), None) { Ok(_) => (), Err(e) => { debug!("Error adding route {}", e);