From 2e418fab4e58eb48c216b39ba0f42f38e38ff972 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 25 Jan 2026 22:42:30 -0300 Subject: [PATCH] http: add production URL detection for BOTSERVER_ENV=production --- src/http_client.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/http_client.rs b/src/http_client.rs index ff0e3dd..cf09017 100644 --- a/src/http_client.rs +++ b/src/http_client.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use std::time::Duration; const DEFAULT_BOTSERVER_URL: &str = "https://localhost:8088"; +const PRODUCTION_BOTSERVER_URL: &str = "https://system.pragmatismo.com.br/"; const DEFAULT_TIMEOUT_SECS: u64 = 30; #[derive(Clone)] @@ -22,7 +23,16 @@ impl BotServerClient { #[must_use] pub fn with_timeout(base_url: Option, timeout: Duration) -> Self { let url = base_url.unwrap_or_else(|| { - std::env::var("BOTSERVER_URL").unwrap_or_else(|_| DEFAULT_BOTSERVER_URL.to_string()) + std::env::var("BOTSERVER_URL").unwrap_or_else(|_| { + 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() @@ -251,4 +261,12 @@ mod tests { assert!(debug_str.contains("BotServerClient")); 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"); + } }