diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cd822d5..cdb8d68b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file. This projec This version includes **multiple breaking changes**. If you are upgrading from v0.15.x and below, please read the [upgrading documentation](https://github.com/stalwartlabs/stalwart/blob/main/UPGRADING/v0_16.md) for more information on how to upgrade from previous versions. ## Added -- New `STALWART_BASE_URL` to override the base URL used in HTTP responses, including port if necessary. +- New `STALWART_HTTP_PORT` to override the HTTP port used in URLs advertised via JMAP and OAuth. ## Changed diff --git a/crates/common/src/config/network.rs b/crates/common/src/config/network.rs index 9250496c..41c262fc 100644 --- a/crates/common/src/config/network.rs +++ b/crates/common/src/config/network.rs @@ -428,12 +428,20 @@ impl Http { Http { url_https: if !bp.registry.is_bootstrap_mode() { - format!("https://{}", bp.registry.base_url().unwrap_or(server_name)) + if let Some(port) = bp.registry.http_port() { + format!("https://{}:{}", server_name, port) + } else { + format!("https://{}", server_name) + } } else { String::new() }, url_http: if !bp.registry.is_bootstrap_mode() { - format!("http://{}", bp.registry.base_url().unwrap_or(server_name)) + if let Some(port) = bp.registry.http_port() { + format!("http://{}:{}", server_name, port) + } else { + format!("http://{}", server_name) + } } else { String::new() }, diff --git a/crates/store/src/build/registry.rs b/crates/store/src/build/registry.rs index 16b86689..9336520c 100644 --- a/crates/store/src/build/registry.rs +++ b/crates/store/src/build/registry.rs @@ -276,8 +276,8 @@ impl RegistryStore { } #[inline(always)] - pub fn base_url(&self) -> Option<&str> { - self.0.env_base_url.as_deref() + pub fn http_port(&self) -> Option { + self.0.env_http_port } #[inline(always)] @@ -323,7 +323,7 @@ impl RegistryStore { env_cluster_role: cluster_role, env_push_shard_id: push_shard_id, env_hostname: hostname, - env_base_url: None, + env_http_port: None, id_generator: utils::snowflake::SnowflakeIdGenerator::new(), }) .await diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index d3f3835e..4151bf83 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -217,7 +217,7 @@ pub struct RegistryStoreInner { pub(crate) env_cluster_role: Option, pub(crate) env_push_shard_id: u32, pub(crate) env_hostname: String, - pub(crate) env_base_url: Option, + pub(crate) env_http_port: Option, pub(crate) id_generator: SnowflakeIdGenerator, } diff --git a/crates/store/src/registry/local.rs b/crates/store/src/registry/local.rs index 92f5c963..374eb24a 100644 --- a/crates/store/src/registry/local.rs +++ b/crates/store/src/registry/local.rs @@ -52,9 +52,10 @@ impl RegistryStoreInner { "localhost".to_string() } }), - env_base_url: std::env::var("STALWART_BASE_URL") + env_http_port: std::env::var("STALWART_HTTP_PORT") .ok() - .filter(|u| !u.is_empty()), + .and_then(|v| v.trim().parse::().ok()) + .filter(|&u| u != 0), } } diff --git a/install.sh b/install.sh index 56a49f84..22a283a0 100644 --- a/install.sh +++ b/install.sh @@ -207,8 +207,8 @@ write_env_file() { # Override the hostname used in HTTP responses #STALWART_HOSTNAME=mail.example.com -# Override the base URL used in HTTP responses, including port if necessary. -#STALWART_BASE_URL=mail.example.com:8080 +# Override the HTTP port used in HTTP responses +#STALWART_HTTP_PORT=8080 # Enable bootstrap / recovery mode on startup. Accepted: 1, true. Default: false. #STALWART_RECOVERY_MODE=true