-
Notifications
You must be signed in to change notification settings - Fork 167
fix(cli): respect SURFPOOL_STUDIO_HOST environment variable for server binding #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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), | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+64
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When
Suggested change
|
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| .unwrap_or(network_binding); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 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); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwrap_or("18488")is unreachable —spliton a non-empty string always yields at least one elementstr::spliton a non-emptynetwork_bindingstring always returns at least one element, so.last()always returnsSome(_), meaning.unwrap_or("18488")can never activate. Ifnetwork_bindingcarries no colon (e.g. a bare hostname),default_portbecomes the wholenetwork_bindingstring and the formatted address will be malformed. Usingrsplit_oncemakes the intent explicit and provides a real fallback.