From 20f6945160c5696a2336aaff7a2483eef0d33fa0 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sat, 27 Feb 2021 13:34:02 -0800 Subject: [PATCH] Fix #140 --- src/main.rs | 13 ++++++++++--- static/manifest.json | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d11c364..5e7eb88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,10 +43,17 @@ where #[async_trait] impl Middleware for NormalizePath { async fn handle(&self, request: Request, next: Next<'_, State>) -> tide::Result { - if !request.url().path().ends_with('/') { - Ok(Response::builder(301).header("Location", format!("{}/", request.url().path())).build()) - } else { + let path = request.url().path(); + let query = request.url().query().unwrap_or_default(); + if path.ends_with('/') { Ok(next.run(request).await) + } else { + let normalized = if query != "" { + format!("{}/?{}", path.replace("//", "/"), query) + } else { + format!("{}/", path.replace("//", "/")) + }; + Ok(redirect(normalized)) } } } diff --git a/static/manifest.json b/static/manifest.json index d56cb96..cf5d31b 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -2,9 +2,9 @@ "name": "Libreddit", "short_name": "Libreddit", "display": "standalone", - "background_color": "#1F1F1F", + "background_color": "#1f1f1f", "description": "An alternative private front-end to Reddit", - "theme_color": "#1F1F1F", + "theme_color": "#1f1f1f", "icons": [ { "src": "logo.png",