Replaced /dry route with a more general /status route
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s
This commit is contained in:
parent
7b3115f5cf
commit
e1260877b6
1 changed files with 14 additions and 14 deletions
26
src/main.rs
26
src/main.rs
|
@ -154,8 +154,8 @@ async fn main() -> std::io::Result<()> {
|
||||||
let mut server = HttpServer::new(move || {
|
let mut server = HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(web::Data::new(config.user.domain_configs.clone()))
|
.app_data(web::Data::new(config.user.domain_configs.clone()))
|
||||||
|
.service(status)
|
||||||
.service(handle)
|
.service(handle)
|
||||||
.service(dry_handle)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for address in config.system.addresses.iter() {
|
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")
|
HttpResponse::NotFound().body("Host not specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/dry")]
|
#[get("/status")]
|
||||||
async fn dry_handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpRequest) -> impl Responder {
|
async fn status(redirects: web::Data<Vec<DomainLinkConfig>>) -> impl Responder {
|
||||||
if let Some(host_raw) = request.headers().get("host") {
|
let mut body_msg = format!("Redirects Loaded: {}", redirects.len());
|
||||||
let host = host_raw.to_str().expect("host conversion to string should never fail");
|
for redirect in redirects.iter() {
|
||||||
println!("{host}");
|
body_msg += "\n[";
|
||||||
for redirect in redirects.iter() {
|
for (idx, domain) in redirect.domains.iter().enumerate() {
|
||||||
if redirect.domains.contains(&host.to_owned()) {
|
body_msg += domain;
|
||||||
let body = format!("Redirecting: {} -> {}", host, redirect.target);
|
if idx != (redirect.domains.len() - 1) {
|
||||||
return HttpResponse::Ok().body(body);
|
body_msg += ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let fail_msg = format!("No Redirect for {host} found");
|
body_msg += format!("] => '{}'", redirect.target).as_str();
|
||||||
return HttpResponse::NotFound().body(fail_msg)
|
|
||||||
}
|
}
|
||||||
HttpResponse::NotFound().body("Host not specified")
|
|
||||||
|
HttpResponse::Ok().body(body_msg)
|
||||||
}
|
}
|
Loading…
Reference in a new issue