use domain vector instead of single string

This commit is contained in:
Neshura 2024-04-08 23:05:25 +02:00
parent c5f2f49c16
commit 0b1ada9221
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -53,7 +53,7 @@ impl Display for Protocol {
#[derive(Clone, Serialize, Deserialize)]
struct DomainLinkConfig {
domain: String,
domains: Vec<String>,
protocol: Protocol,
target: String,
}
@ -195,7 +195,7 @@ async fn handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpReques
let host = host_raw.to_str().expect("host conversion to string should never fail");
println!("{host}");
for redirect in redirects.iter() {
if redirect.domain == host {
if redirect.domains.contains(&host.to_owned()) {
return HttpResponse::PermanentRedirect().insert_header(("location", format!("{}{}", redirect.protocol, redirect.target).as_str())).finish();
}
}
@ -211,7 +211,7 @@ async fn dry_handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpRe
let host = host_raw.to_str().expect("host conversion to string should never fail");
println!("{host}");
for redirect in redirects.iter() {
if redirect.domain == host {
if redirect.domains.contains(&host.to_owned()) {
let body = format!("Redirecting: {} -> {}{}", host, redirect.protocol, redirect.target);
return HttpResponse::Ok().body(body);
}