Replaced STALWART_HTTPS_PORT with STALWART_PUBLIC_URL
This commit is contained in:
@@ -274,8 +274,8 @@ impl RegistryStore {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn https_port(&self) -> Option<u16> {
|
||||
self.0.env_https_port
|
||||
pub fn public_url(&self) -> Option<&str> {
|
||||
self.0.env_public_url.as_deref()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -305,9 +305,9 @@ impl RegistryStore {
|
||||
}
|
||||
|
||||
#[cfg(feature = "test_mode")]
|
||||
pub fn clone_with_port(&self, store: u16) -> Self {
|
||||
pub fn clone_with_public_url(&self, url: String) -> Self {
|
||||
let mut inner = self.0.as_ref().clone();
|
||||
inner.env_https_port = Some(store);
|
||||
inner.env_public_url = Some(url);
|
||||
Self(inner.into())
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ impl RegistryStore {
|
||||
env_cluster_role: cluster_role,
|
||||
env_push_shard_id: push_shard_id,
|
||||
env_hostname: hostname,
|
||||
env_https_port: None,
|
||||
env_public_url: None,
|
||||
id_generator: utils::snowflake::SnowflakeIdGenerator::new(),
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -217,7 +217,7 @@ pub struct RegistryStoreInner {
|
||||
pub(crate) env_cluster_role: Option<String>,
|
||||
pub(crate) env_push_shard_id: u32,
|
||||
pub(crate) env_hostname: String,
|
||||
pub(crate) env_https_port: Option<u16>,
|
||||
pub(crate) env_public_url: Option<String>,
|
||||
pub(crate) id_generator: SnowflakeIdGenerator,
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,19 @@ pub(crate) enum RegistryInit {
|
||||
|
||||
impl RegistryStoreInner {
|
||||
pub(crate) fn new(local_path: PathBuf) -> Self {
|
||||
let env_hostname = std::env::var("STALWART_HOSTNAME")
|
||||
.ok()
|
||||
.filter(|h| !h.is_empty())
|
||||
.unwrap_or_else(|| {
|
||||
let host = gethostname::gethostname();
|
||||
let host = host.to_string_lossy();
|
||||
if host.parse::<IpAddr>().is_err() {
|
||||
host.to_lowercase()
|
||||
} else {
|
||||
"localhost".to_string()
|
||||
}
|
||||
});
|
||||
|
||||
Self {
|
||||
local_path,
|
||||
store: Store::None,
|
||||
@@ -40,21 +53,18 @@ impl RegistryStoreInner {
|
||||
.ok()
|
||||
.and_then(|id| id.parse::<u32>().ok().and_then(|v| v.checked_sub(1)))
|
||||
.unwrap_or(0),
|
||||
env_hostname: std::env::var("STALWART_HOSTNAME")
|
||||
env_public_url: std::env::var("STALWART_PUBLIC_URL")
|
||||
.ok()
|
||||
.filter(|h| !h.is_empty())
|
||||
.unwrap_or_else(|| {
|
||||
let host = gethostname::gethostname();
|
||||
let host = host.to_string_lossy();
|
||||
if host.parse::<IpAddr>().is_err() {
|
||||
host.to_lowercase()
|
||||
} else {
|
||||
"localhost".to_string()
|
||||
}
|
||||
.map(|v| v.trim().trim_end_matches('/').to_string())
|
||||
.filter(|u| !u.is_empty())
|
||||
.or_else(|| {
|
||||
std::env::var("STALWART_HTTPS_PORT").ok().and_then(|p| {
|
||||
p.parse::<u16>()
|
||||
.ok()
|
||||
.map(|port| format!("https://{}:{}", env_hostname, port))
|
||||
})
|
||||
}),
|
||||
env_https_port: std::env::var("STALWART_HTTPS_PORT")
|
||||
.ok()
|
||||
.and_then(|p| p.parse::<u16>().ok()),
|
||||
env_hostname,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user