remove protocol settings
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
This commit is contained in:
parent
0b1ada9221
commit
8e077609e9
1 changed files with 2 additions and 18 deletions
20
src/main.rs
20
src/main.rs
|
@ -36,25 +36,9 @@ macro_rules! error {
|
|||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
enum Protocol {
|
||||
Http,
|
||||
Https
|
||||
}
|
||||
|
||||
impl Display for Protocol {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Protocol::Http => write!(f, "http://"),
|
||||
Protocol::Https => write!(f, "https://")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
struct DomainLinkConfig {
|
||||
domains: Vec<String>,
|
||||
protocol: Protocol,
|
||||
target: String,
|
||||
}
|
||||
|
||||
|
@ -196,7 +180,7 @@ async fn handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpReques
|
|||
println!("{host}");
|
||||
for redirect in redirects.iter() {
|
||||
if redirect.domains.contains(&host.to_owned()) {
|
||||
return HttpResponse::PermanentRedirect().insert_header(("location", format!("{}{}", redirect.protocol, redirect.target).as_str())).finish();
|
||||
return HttpResponse::PermanentRedirect().insert_header(("location", redirect.target.to_string().as_str())).finish();
|
||||
}
|
||||
}
|
||||
let fail_msg = format!("No Redirect for {host} found");
|
||||
|
@ -212,7 +196,7 @@ async fn dry_handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpRe
|
|||
println!("{host}");
|
||||
for redirect in redirects.iter() {
|
||||
if redirect.domains.contains(&host.to_owned()) {
|
||||
let body = format!("Redirecting: {} -> {}{}", host, redirect.protocol, redirect.target);
|
||||
let body = format!("Redirecting: {} -> {}", host, redirect.target);
|
||||
return HttpResponse::Ok().body(body);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue