Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ pub async fn create_http_client(
.set_port(Some(port))
.unwrap_or_else(|_| panic!("error setting port: {port}"));

// Apply path prefix if configured
if let Some(prefix) = &service_config.path_prefix {
let trimmed = prefix.trim_matches('/');
if !trimmed.is_empty() {
base_url.set_path(&format!("/{}", trimmed));
}
}

let connect_timeout = Duration::from_secs(DEFAULT_CONNECT_TIMEOUT_SEC);
let request_timeout = Duration::from_secs(
service_config
Expand Down
6 changes: 6 additions & 0 deletions src/clients/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ pub struct HttpClient {

impl HttpClient {
pub fn new(base_url: Url, api_token: Option<String>, inner: HttpClientInner) -> Self {
// Ensure base_url has trailing slash for proper path joining
let mut base_url = base_url;
if !base_url.path().ends_with('/') {
base_url.set_path(&format!("{}/", base_url.path()));
}
let health_url = base_url.join("health").unwrap();
Self {
base_url,
Expand All @@ -139,6 +144,7 @@ impl HttpClient {
}

pub fn endpoint(&self, path: &str) -> Url {
let path = path.trim_start_matches('/');
self.base_url.join(path).unwrap()
}

Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub struct ServiceConfig {
pub hostname: String,
/// Port for service
pub port: Option<u16>,
/// Path prefix for service endpoints (e.g., "/namespace/service-name")
pub path_prefix: Option<String>,
/// Timeout in seconds for request to be handled
pub request_timeout: Option<u64>,
/// TLS provider info
Expand All @@ -99,6 +101,7 @@ impl ServiceConfig {
Self {
hostname,
port: Some(port),
path_prefix: None,
request_timeout: None,
tls: None,
grpc_dns_probe_interval: None,
Expand Down