revert: removing production URL constant and detection (requested by user)
This commit is contained in:
parent
2e418fab4e
commit
bfaa68dc35
1 changed files with 1 additions and 19 deletions
|
|
@ -5,7 +5,6 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
const DEFAULT_BOTSERVER_URL: &str = "https://localhost:8088";
|
const DEFAULT_BOTSERVER_URL: &str = "https://localhost:8088";
|
||||||
const PRODUCTION_BOTSERVER_URL: &str = "https://system.pragmatismo.com.br/";
|
|
||||||
const DEFAULT_TIMEOUT_SECS: u64 = 30;
|
const DEFAULT_TIMEOUT_SECS: u64 = 30;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -23,16 +22,7 @@ impl BotServerClient {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_timeout(base_url: Option<String>, timeout: Duration) -> Self {
|
pub fn with_timeout(base_url: Option<String>, timeout: Duration) -> Self {
|
||||||
let url = base_url.unwrap_or_else(|| {
|
let url = base_url.unwrap_or_else(|| {
|
||||||
std::env::var("BOTSERVER_URL").unwrap_or_else(|_| {
|
std::env::var("BOTSERVER_URL").unwrap_or_else(|_| DEFAULT_BOTSERVER_URL.to_string())
|
||||||
let is_prod = std::env::var("BOTSERVER_ENV")
|
|
||||||
.map(|v| v == "production" || v == "prod")
|
|
||||||
.unwrap_or(false);
|
|
||||||
if is_prod {
|
|
||||||
PRODUCTION_BOTSERVER_URL.to_string()
|
|
||||||
} else {
|
|
||||||
DEFAULT_BOTSERVER_URL.to_string()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
|
|
@ -261,12 +251,4 @@ mod tests {
|
||||||
assert!(debug_str.contains("BotServerClient"));
|
assert!(debug_str.contains("BotServerClient"));
|
||||||
assert!(debug_str.contains("http://debug-test"));
|
assert!(debug_str.contains("http://debug-test"));
|
||||||
}
|
}
|
||||||
#[test]
|
|
||||||
fn test_client_production_url() {
|
|
||||||
std::env::remove_var("BOTSERVER_URL");
|
|
||||||
std::env::set_var("BOTSERVER_ENV", "production");
|
|
||||||
let client = BotServerClient::new(None);
|
|
||||||
assert_eq!(client.base_url(), PRODUCTION_BOTSERVER_URL);
|
|
||||||
std::env::remove_var("BOTSERVER_ENV");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue