From f526e7ec5b356cc34d0dd2d0ec677d946734151b Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Thu, 28 Mar 2024 13:27:33 -0500 Subject: [PATCH] chg: 404 response doesn't change the url --- actix/src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/actix/src/main.rs b/actix/src/main.rs index 40cc920..8d5901f 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -6,7 +6,7 @@ use actix_web::{ http::StatusCode, middleware, post, web::{self, Redirect}, - App, HttpResponse, HttpServer, Responder, + App, Either, HttpResponse, HttpServer, Responder, }; use rusqlite::Connection; use std::env; @@ -82,13 +82,18 @@ async fn link_handler(shortlink: web::Path, data: web::Data) - let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT")); database::add_hit(shortlink.as_str(), &data.db); if redirect_method == "TEMPORARY" { - Redirect::to(longlink) + Either::Left(Redirect::to(longlink)) } else { // Defaults to permanent redirection - Redirect::to(longlink).permanent() + Either::Left(Redirect::to(longlink).permanent()) } } else { - Redirect::to("/err/404") + Either::Right( + NamedFile::open_async("./resources/static/404.html") + .await + .customize() + .with_status(StatusCode::NOT_FOUND), + ) } }