From 74f3fddd01698dba0f4d01fc0865c548eb110961 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 28 Apr 2023 12:12:31 -0500 Subject: [PATCH] Fixed the 404 error page display --- actix/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/actix/src/main.rs b/actix/src/main.rs index ce97c8e..3553421 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -60,7 +60,10 @@ async fn siteurl(session: Session) -> HttpResponse { // 404 error page #[get("/err/404")] 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 @@ -69,7 +72,7 @@ async fn link_handler(shortlink: web::Path, data: web::Data) - let shortlink_str = shortlink.to_string(); let longlink = utils::get_longurl(shortlink_str, &data.db); if longlink == *"" { - Redirect::to("/err/404").using_status_code(StatusCode::NOT_FOUND) + Redirect::to("/err/404") } else { let redirect_method = env::var("redirect_method").unwrap_or("PERMANENT".to_string()); database::add_hit(shortlink.as_str(), &data.db);