From 76ab00c47a874362b894f451776927b95d055e46 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 17 Aug 2023 17:29:21 +0200 Subject: [PATCH] Fix local worker not connecting --- src/config.rs | 22 +++++++++++++--------- src/main.rs | 7 ++----- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index dfcad34..6103aa5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,11 +118,10 @@ pub struct ServerConfig { pub repo_fetch_refspecs: Vec, pub repo_fetch_url: Option, pub web_address: SocketAddr, - /// Always ends without a `/`. + /// Always starts with a `/` and ends without a `/`, preferring the latter. /// /// This means that you can prefix the base onto an absolute path and get - /// another absolute path. You could also use an url here if you have a - /// weird reason to do so. + /// another absolute path. pub web_base: String, pub worker_token: String, pub worker_timeout: Duration, @@ -145,18 +144,23 @@ impl ServerConfig { "unnamed repo".to_string() } + fn web_base(mut base: String) -> String { + if !base.starts_with('/') { + base.insert(0, '/'); + } + if base.ends_with('/') { + base.pop(); + } + base + } + fn from_raw_server(raw: RawServer, args: &Args) -> Self { let repo_name = match raw.repo.name { Some(name) => name, None => Self::repo_name(args), }; - let web_base = raw - .web - .base - .strip_suffix('/') - .unwrap_or(&raw.web.base) - .to_string(); + let web_base = Self::web_base(raw.web.base); let worker_token = match raw.worker.token { Some(token) => token, diff --git a/src/main.rs b/src/main.rs index 59ac55d..ca1da85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,11 +99,7 @@ fn local_url(config: &ServerConfig) -> String { }; let port = config.web_address.port(); let base = &config.web_base; - if base.starts_with('/') { - format!("http://{host}:{port}{base}") - } else { - format!("http://{host}:{port}/{base}") - } + format!("http://{host}:{port}{base}") } async fn open_in_browser(config: &ServerConfig) { @@ -137,6 +133,7 @@ async fn launch_local_workers(config: &'static Config, amount: u8) { let worker_config = Box::leak(Box::new(worker_config)); info!("Starting local worker {}", worker_config.name); + trace!("Worker config: {worker_config:#?}"); let worker = Worker::new(worker_config); tokio::spawn(async move { worker.run().await }); }