Add option for temporary redirection

This commit is contained in:
SinTan1729
2023-04-28 00:22:30 -05:00
parent ca01676916
commit f3984624d9
3 changed files with 17 additions and 2 deletions

View File

@@ -71,8 +71,14 @@ async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -
if longlink == *"" {
Redirect::to("/err/404").using_status_code(StatusCode::NOT_FOUND)
} else {
let redirect_method = env::var("redirect_method").unwrap_or("PERMANENT".to_string());
database::add_hit(shortlink.as_str(), &data.db);
Redirect::to(longlink).permanent()
if redirect_method == *"TEMPORARY" {
Redirect::to(longlink)
} else {
// Defaults to permanent redirection
Redirect::to(longlink).permanent()
}
}
}