From f9eec315d8745a1bb0d4de9b811bd4cea4006d9d Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 1 Apr 2022 02:45:15 -0700 Subject: fix(database): always use trailing slash root --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 4c3d33b..74f613f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,21 +93,26 @@ async fn main() -> Result<(), Box> { url.to_string(), ); - let previous_database = (*DATABASE.lock().unwrap()).get::(url.path()); + let mut url_path = url.path(); + if url.path().is_empty() { + url_path = "/"; + } + + let previous_database = (*DATABASE.lock().unwrap()).get::(url_path); match previous_database { None => { (*DATABASE.lock().unwrap()) - .set::(url.path(), &0) + .set::(url_path, &0) .unwrap(); } Some(_) => {} } - let new_database = (*DATABASE.lock().unwrap()).get::(url.path()); + let new_database = (*DATABASE.lock().unwrap()).get::(url_path); (*DATABASE.lock().unwrap()) - .set(url.path(), &(new_database.unwrap() + 1)) + .set(url_path, &(new_database.unwrap() + 1)) .unwrap(); })); router.set_error_handler(Box::new(|_| { -- cgit v1.2.3