aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/routes.rs11
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,