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:
@@ -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/
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user