Fix #140
This commit is contained in:
parent
10c73fad7f
commit
20f6945160
13
src/main.rs
13
src/main.rs
@ -43,10 +43,17 @@ where
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<State: Clone + Send + Sync + 'static> Middleware<State> for NormalizePath {
|
impl<State: Clone + Send + Sync + 'static> Middleware<State> for NormalizePath {
|
||||||
async fn handle(&self, request: Request<State>, next: Next<'_, State>) -> tide::Result {
|
async fn handle(&self, request: Request<State>, next: Next<'_, State>) -> tide::Result {
|
||||||
if !request.url().path().ends_with('/') {
|
let path = request.url().path();
|
||||||
Ok(Response::builder(301).header("Location", format!("{}/", request.url().path())).build())
|
let query = request.url().query().unwrap_or_default();
|
||||||
} else {
|
if path.ends_with('/') {
|
||||||
Ok(next.run(request).await)
|
Ok(next.run(request).await)
|
||||||
|
} else {
|
||||||
|
let normalized = if query != "" {
|
||||||
|
format!("{}/?{}", path.replace("//", "/"), query)
|
||||||
|
} else {
|
||||||
|
format!("{}/", path.replace("//", "/"))
|
||||||
|
};
|
||||||
|
Ok(redirect(normalized))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
"name": "Libreddit",
|
"name": "Libreddit",
|
||||||
"short_name": "Libreddit",
|
"short_name": "Libreddit",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"background_color": "#1F1F1F",
|
"background_color": "#1f1f1f",
|
||||||
"description": "An alternative private front-end to Reddit",
|
"description": "An alternative private front-end to Reddit",
|
||||||
"theme_color": "#1F1F1F",
|
"theme_color": "#1f1f1f",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "logo.png",
|
"src": "logo.png",
|
||||||
|
Loading…
Reference in New Issue
Block a user