Compare commits

...

3 Commits
ci ... no-proxy

Author SHA1 Message Date
Brendan Allan
3779d0fc47 cleanup 2026-01-21 16:20:51 +08:00
Brendan Allan
e8531c8bd9 cleanup 2026-01-21 16:03:57 +08:00
Adam
fee84b69c6 fix(desktop): no proxy for connecting to sidecar 2026-01-20 14:47:22 -06:00

View File

@@ -156,6 +156,7 @@ fn spawn_sidecar(app: &AppHandle, port: u32, password: &str) -> CommandChild {
println!("spawning sidecar on port {port}");
let (mut rx, child) = cli::create_command(app, format!("serve --port {port}").as_str())
.env("OPENCODE_SERVER_USERNAME", "opencode")
.env("OPENCODE_SERVER_PASSWORD", password)
.spawn()
.expect("Failed to spawn opencode");
@@ -197,17 +198,37 @@ fn spawn_sidecar(app: &AppHandle, port: u32, password: &str) -> CommandChild {
child
}
async fn check_server_health(url: &str, password: Option<&str>) -> bool {
let health_url = format!("{}/global/health", url.trim_end_matches('/'));
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(3))
.build();
fn url_is_localhost(url: &reqwest::Url) -> bool {
url.host_str().is_some_and(|host| {
host.eq_ignore_ascii_case("localhost")
|| host
.parse::<std::net::IpAddr>()
.is_ok_and(|ip| ip.is_loopback())
})
}
let Ok(client) = client else {
async fn check_server_health(url: &str, password: Option<&str>) -> bool {
let Ok(url) = reqwest::Url::parse(url) else {
return false;
};
let mut req = client.get(&health_url);
let mut builder = reqwest::Client::builder().timeout(Duration::from_secs(3));
if url_is_localhost(&url) {
// Some environments set proxy variables (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY) without
// excluding loopback. reqwest respects these by default, which can prevent the desktop
// app from reaching its own local sidecar server.
builder = builder.no_proxy();
};
let Ok(client) = builder.build() else {
return false;
};
let Ok(health_url) = url.join("/global/health") else {
return false;
};
let mut req = client.get(health_url);
if let Some(password) = password {
req = req.basic_auth("opencode", Some(password));