From 6f9ef9be699d2568d5bc234df4e69f0ecfdf3aab Mon Sep 17 00:00:00 2001 From: blek Date: Thu, 26 Oct 2023 18:30:21 +1000 Subject: [PATCH] fix proxy ip getter --- filed/src/env.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/filed/src/env.rs b/filed/src/env.rs index a7532f1..545dac4 100644 --- a/filed/src/env.rs +++ b/filed/src/env.rs @@ -45,6 +45,7 @@ pub fn loadenv() -> Result> { let env_var = get_var::<&str, String>("PROXY_IP")?; let ip = env_var.parse::(); + let ret = if let Ok(ip) = ip { if ip == IpAddr::from([127, 0, 0, 1]) { log::warn!("Proxy address is 127.0.0.1. No proxy will be trusted") @@ -56,6 +57,13 @@ pub fn loadenv() -> Result> { } ip } else { + let mut env_var = env_var; + + // add port if not added + if env_var.split(":").collect::>().len() == 1 { + env_var.push_str(":80"); + } + let sock = env_var.to_socket_addrs(); if let Err(err) = sock { return Err(format!("Can't resolve {env_var}: {:?}", err).into()); @@ -64,8 +72,15 @@ pub fn loadenv() -> Result> { if addrs.len() == 0 { return Err(format!("{env_var} resolved to nothing").into()); } - addrs.next().unwrap().ip() + let addr = addrs.next().unwrap().ip(); + addr + }; + #[cfg(debug_assertions)] { + if ret != IpAddr::from([ 127, 0, 0, 1 ]) { + log::debug!("Proxy ip is {}", ret) + } } + ret }, redis: Redis { pass: get_var("REDIS_PASS")?,