Fixed the 404 error page display

This commit is contained in:
SinTan1729 2023-04-28 12:12:31 -05:00
parent 8be3e54861
commit 74f3fddd01

View File

@ -60,7 +60,10 @@ async fn siteurl(session: Session) -> HttpResponse {
// 404 error page // 404 error page
#[get("/err/404")] #[get("/err/404")]
async fn error404() -> impl Responder { async fn error404() -> impl Responder {
NamedFile::open_async("./resources/static/404.html").await NamedFile::open_async("./resources/static/404.html")
.await
.customize()
.with_status(StatusCode::NOT_FOUND)
} }
// Handle a given shortlink // Handle a given shortlink
@ -69,7 +72,7 @@ async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -
let shortlink_str = shortlink.to_string(); let shortlink_str = shortlink.to_string();
let longlink = utils::get_longurl(shortlink_str, &data.db); let longlink = utils::get_longurl(shortlink_str, &data.db);
if longlink == *"" { if longlink == *"" {
Redirect::to("/err/404").using_status_code(StatusCode::NOT_FOUND) Redirect::to("/err/404")
} else { } else {
let redirect_method = env::var("redirect_method").unwrap_or("PERMANENT".to_string()); let redirect_method = env::var("redirect_method").unwrap_or("PERMANENT".to_string());
database::add_hit(shortlink.as_str(), &data.db); database::add_hit(shortlink.as_str(), &data.db);