Skip to content

Commit

Permalink
Rename override_urls => urls_override
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Jun 22, 2024
1 parent df1cf36 commit 4b40128
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ domains:
- url: https://eth.llamarpc.com
headers:
x-api-key: test
# override_urls:
# urls_override:
# "/":
# url: https://rpc.ankr.com/eth
# override_urls:
# urls_override:
# "/":
# url: https://rpc.ankr.com/eth
#headers:
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ impl NodeConfig {
pub struct Domain {
pub domain: String,
pub urls: Vec<Url>,
pub override_urls: Option<HashMap<String, Url>>,
pub urls_override: Option<HashMap<String, Url>>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Url {
pub url: String,
pub headers: Option<HashMap<String, String>>,
pub override_urls: Option<HashMap<String, Url>>,
pub urls_override: Option<HashMap<String, Url>>,
}

impl NodeConfig {
Expand Down
8 changes: 4 additions & 4 deletions src/node_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Service<Request<IncomingBody>> for NodeService {
let url = domain.urls.first().unwrap().clone();
let url = uri(
url,
domain.override_urls.clone().unwrap_or_default(),
domain.urls_override.clone().unwrap_or_default(),
req.uri(),
);

Expand All @@ -57,14 +57,14 @@ impl Service<Request<IncomingBody>> for NodeService {
}
}

fn uri(url: Url, override_urls: HashMap<String, Url>, original_uri: &Uri) -> RequestUrl {
fn uri(url: Url, urls_override: HashMap<String, Url>, original_uri: &Uri) -> RequestUrl {
let uri = url.url + original_uri.to_string().as_str();
let uri = uri.parse::<hyper::Uri>().expect("invalid url");

// first order is url and the global
let override_urls = vec![url.override_urls.unwrap_or_default(), override_urls];
let urls_override = vec![url.urls_override.unwrap_or_default(), urls_override];

for override_url in override_urls {
for override_url in urls_override {
for (path, endpoint) in override_url {
if uri.path() == path {
let uri = Uri::from_str(&endpoint.url.clone().as_str()).unwrap();
Expand Down

0 comments on commit 4b40128

Please sign in to comment.