From e1260877b6d2c9b3961091685c2d683b7129c32b Mon Sep 17 00:00:00 2001 From: Neshura Date: Wed, 10 Apr 2024 18:54:21 +0200 Subject: [PATCH] Replaced /dry route with a more general /status route --- src/main.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7a30947..5ff6651 100644 --- a/src/main.rs +++ b/src/main.rs @@ -154,8 +154,8 @@ async fn main() -> std::io::Result<()> { let mut server = HttpServer::new(move || { App::new() .app_data(web::Data::new(config.user.domain_configs.clone())) + .service(status) .service(handle) - .service(dry_handle) }); for address in config.system.addresses.iter() { @@ -189,19 +189,19 @@ async fn handle(redirects: web::Data>, request: HttpReques HttpResponse::NotFound().body("Host not specified") } -#[get("/dry")] -async fn dry_handle(redirects: web::Data>, request: HttpRequest) -> impl Responder { - if let Some(host_raw) = request.headers().get("host") { - let host = host_raw.to_str().expect("host conversion to string should never fail"); - println!("{host}"); - for redirect in redirects.iter() { - if redirect.domains.contains(&host.to_owned()) { - let body = format!("Redirecting: {} -> {}", host, redirect.target); - return HttpResponse::Ok().body(body); +#[get("/status")] +async fn status(redirects: web::Data>) -> impl Responder { + let mut body_msg = format!("Redirects Loaded: {}", redirects.len()); + for redirect in redirects.iter() { + body_msg += "\n["; + for (idx, domain) in redirect.domains.iter().enumerate() { + body_msg += domain; + if idx != (redirect.domains.len() - 1) { + body_msg += ", "; } } - let fail_msg = format!("No Redirect for {host} found"); - return HttpResponse::NotFound().body(fail_msg) + body_msg += format!("] => '{}'", redirect.target).as_str(); } - HttpResponse::NotFound().body("Host not specified") -} + + HttpResponse::Ok().body(body_msg) +} \ No newline at end of file