diff --git a/backend/src/infra.rs b/backend/src/infra.rs index ecd5c3d..ff375a0 100644 --- a/backend/src/infra.rs +++ b/backend/src/infra.rs @@ -281,11 +281,7 @@ async fn try_sync_relay(relay: &Relay) -> Result<()> { .await? .is_none(); - let host = if relay.custom_domain_verified == 1 && !relay.custom_domain.is_empty() { - relay.custom_domain.clone() - } else { - format!("{}.{}", relay.subdomain, env::get().relay_domain) - }; + let host = relay.host(); let mut body = serde_json::json!({ "host": host, diff --git a/backend/src/models.rs b/backend/src/models.rs index 18bb64b..a451a9b 100644 --- a/backend/src/models.rs +++ b/backend/src/models.rs @@ -96,6 +96,18 @@ pub struct Relay { pub created_at: i64, } +impl Relay { + /// The relay's effective public host: its verified custom domain when set, + /// otherwise its canonical `.`. + pub fn host(&self) -> String { + if self.custom_domain_verified == 1 && !self.custom_domain.is_empty() { + self.custom_domain.clone() + } else { + format!("{}.{}", self.subdomain, crate::env::get().relay_domain) + } + } +} + impl Default for Relay { fn default() -> Self { Self {