summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKornel <kornel@geekhood.net>2020-04-04 18:28:18 +0100
committerKornel <kornel@geekhood.net>2020-04-04 18:28:18 +0100
commitc75a4ec96deaaf5bc9978715948f511d4a4b156a (patch)
treef1ada0b4bb0faafc6a1aa5a2121b07bf1cdae0b5
parent905b34ff0d303afd676df2d2be2416b2877c9fe8 (diff)
Redir crates url
-rw-r--r--server/src/main.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index cc00495..2860531 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -175,6 +175,7 @@ async fn run_server() -> Result<(), failure::Error> {
.route("/", web::get().to(handle_home))
.route("/search", web::get().to(handle_search))
.route("/index", web::get().to(handle_search)) // old crates.rs/index url
+ .route("/categories/{rest:.*}", web::get().to(handle_redirect))
.route("/new", web::get().to(handle_new_trending))
.route("/keywords/{keyword}", web::get().to(handle_keyword))
.route("/crates/{crate}", web::get().to(handle_crate))
@@ -358,6 +359,12 @@ async fn handle_gitlab_crate(req: HttpRequest) -> Result<HttpResponse, ServerErr
handle_git_crate(req, "lab").await
}
+async fn handle_redirect(req: HttpRequest) -> HttpResponse {
+ let inf = req.match_info();
+ let rest = inf.query("rest");
+ HttpResponse::PermanentRedirect().header("Location", format!("/{}", rest)).body("")
+}
+
async fn handle_git_crate(req: HttpRequest, slug: &'static str) -> Result<HttpResponse, ServerError> {
let inf = req.match_info();
let state: &AServerState = req.app_data().expect("appdata");