Replaced /dry route with a more general /status route
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s

This commit is contained in:
Neshura 2024-04-10 18:54:21 +02:00
parent 7b3115f5cf
commit e1260877b6
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -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<Vec<DomainLinkConfig>>, request: HttpReques
HttpResponse::NotFound().body("Host not specified")
}
#[get("/dry")]
async fn dry_handle(redirects: web::Data<Vec<DomainLinkConfig>>, 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}");
#[get("/status")]
async fn status(redirects: web::Data<Vec<DomainLinkConfig>>) -> impl Responder {
let mut body_msg = format!("Redirects Loaded: {}", redirects.len());
for redirect in redirects.iter() {
if redirect.domains.contains(&host.to_owned()) {
let body = format!("Redirecting: {} -> {}", host, redirect.target);
return HttpResponse::Ok().body(body);
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)
}