diff options
author | Joris | 2025-02-13 22:53:35 +0100 |
---|---|---|
committer | Joris | 2025-02-13 22:53:35 +0100 |
commit | b2c4e27a7a8166ace2ae302b6c1e022bfc8274bb (patch) | |
tree | 03c0f5d160204c44cbaaf2c0f0d2049427218e33 /src/routes.rs | |
parent | ede6d7a5d89f3a6c33dbf17e0ba86dd36372cdf6 (diff) |
Remove trailing slash in routermain
Diffstat (limited to 'src/routes.rs')
-rw-r--r-- | src/routes.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/routes.rs b/src/routes.rs index 3b3fc9a..ae97b7a 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -23,11 +23,12 @@ pub async fn routes( authorized_key: String, files_dir: String, ) -> Result<Response<BoxBody<Bytes, std::io::Error>>> { - let path = &request.uri().path().split('/').collect::<Vec<&str>>()[1..]; + let path = remove_trailing_slash(request.uri().path()); + let path_parts = &path.split('/').collect::<Vec<&str>>()[1..]; let files_dir = Path::new(&files_dir); - match (request.method(), path) { - (&Method::GET, [""]) => Ok(html(templates::INDEX)), + match (request.method(), path_parts) { + (&Method::GET, []) => Ok(html(templates::INDEX)), (&Method::GET, ["static", "main.js"]) => Ok(static_file( include_str!("static/main.js"), "application/javascript", @@ -48,6 +49,10 @@ pub async fn routes( } } +fn remove_trailing_slash(str: &str) -> String { + str.to_string().strip_suffix("/").unwrap_or(str).to_string() +} + async fn upload_file( request: Request<Incoming>, db_conn: Connection, |