From b34a6fff6dfdfcb3ca17282414607cd210a8087a Mon Sep 17 00:00:00 2001 From: Amit5601 Date: Wed, 24 Jun 2026 07:20:29 +0000 Subject: [PATCH] fix(cli): respect SURFPOOL_STUDIO_HOST environment variable for server binding --- crates/cli/src/http/mod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/http/mod.rs b/crates/cli/src/http/mod.rs index 2c09221ef..b6fd726b4 100644 --- a/crates/cli/src/http/mod.rs +++ b/crates/cli/src/http/mod.rs @@ -51,6 +51,25 @@ pub async fn start_studio_and_scenario_server( let template_registry_wrapped = Data::new(RwLock::new(TemplateRegistry::new())); let loaded_scenarios = Data::new(RwLock::new(LoadedScenarios::new())); + let default_port = network_binding.split(':').last().unwrap_or("18488"); + let final_bind_addr = std::env::var("SURFPOOL_STUDIO_HOST") + .map(|host| { + if host.contains(']') { + if host.rfind(':') > host.rfind(']') { + host + } else { + format!("{}:{}", host, default_port) + } + } else { + match host.matches(':').count() { + 0 => format!("{}:{}", host, default_port), + 1 => host, + _ => format!("[{}]:{}", host, default_port), + } + } + }) + .unwrap_or(network_binding); + let server = HttpServer::new(move || { let mut app = App::new() .app_data(config_wrapped.clone()) @@ -81,7 +100,7 @@ pub async fn start_studio_and_scenario_server( app }) .workers(5) - .bind(network_binding)? + .bind(final_bind_addr)? .run(); let handle = server.handle(); tokio::spawn(server);