Network Explorer API: add env var GEO_IP_SERVICE_API_KEY to provide an API key for https://freegeoip.app/

This commit is contained in:
Mark Sinclair
2021-10-05 17:41:38 +01:00
parent 4307756719
commit 7e581183f4
2 changed files with 14 additions and 2 deletions
+5 -1
View File
@@ -14,4 +14,8 @@ TODO:
* grab mixnode description info via reqwest and serve it (avoid mixed-content errors)
* serve it all over http
* dependency injection
* tests
* tests
## Running
- Supply the environment variable `GEO_IP_SERVICE_API_KEY` with a key from https://freegeoip.app/
+9 -1
View File
@@ -90,7 +90,15 @@ impl CountryStatistics {
}
async fn locate(ip: &str) -> Result<GeoLocation, ReqwestError> {
let response = reqwest::get(format!("{}{}", crate::GEO_IP_SERVICE, ip)).await?;
let api_key = ::std::env::var("GEO_IP_SERVICE_API_KEY")
.expect("Env var GEO_IP_SERVICE_API_KEY is not set");
let response = reqwest::get(format!(
"{}{}?apikey={}",
crate::GEO_IP_SERVICE,
ip,
api_key
))
.await?;
let location = response.json::<GeoLocation>().await?;
Ok(location)
}