Skip to content

Commit

Permalink
Merge branch 'refs/heads/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed May 15, 2024
2 parents 2387bc0 + 7f9768a commit d4fe1eb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,40 @@ 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();

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) => {
debug!("Error adding const route {}", e);
}
}
} 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);
Expand Down

0 comments on commit d4fe1eb

Please sign in to comment.