best address logic

This commit is contained in:
Aiden McClelland
2025-08-07 17:15:23 -06:00
parent 4d5ff1a97b
commit 3845550e90
9 changed files with 119 additions and 107 deletions

View File

@@ -194,7 +194,12 @@ pub async fn add_domain<Kind: HostApiKind>(
.as_domains()
.keys()?
.into_iter()
.find(|root| domain.ends_with(&**root))
.find(|root| {
domain == root
|| domain
.strip_suffix(&**root)
.map_or(false, |d| d.ends_with("."))
})
.or_not_found(lazy_format!("root domain for {domain}"))?;
if let Some(acme) = &acme {
@@ -209,7 +214,6 @@ pub async fn add_domain<Kind: HostApiKind>(
}
}
Kind::host_for(&inheritance, db)?.as_domains_mut().insert(
domain,
&DomainConfig {

View File

@@ -385,8 +385,7 @@ impl NetServiceData {
gateway_id: interface.clone(),
public, // TODO: check if port forward is active
hostname: IpHostname::Domain {
domain: address.clone(),
subdomain: None,
value: address.clone(),
port: None,
ssl_port: Some(443),
},
@@ -396,8 +395,7 @@ impl NetServiceData {
gateway_id: interface.clone(),
public,
hostname: IpHostname::Domain {
domain: address.clone(),
subdomain: None,
value: address.clone(),
port: bind.net.assigned_port,
ssl_port: bind.net.assigned_ssl_port,
},

View File

@@ -72,9 +72,7 @@ pub enum IpHostname {
},
Domain {
#[ts(type = "string")]
domain: InternedString,
#[ts(type = "string | null")]
subdomain: Option<InternedString>,
value: InternedString,
port: Option<u16>,
ssl_port: Option<u16>,
},
@@ -85,15 +83,7 @@ impl IpHostname {
Self::Ipv4 { value, .. } => InternedString::from_display(value),
Self::Ipv6 { value, .. } => InternedString::from_display(value),
Self::Local { value, .. } => value.clone(),
Self::Domain {
domain, subdomain, ..
} => {
if let Some(subdomain) = subdomain {
InternedString::from_display(&lazy_format!("{subdomain}.{domain}"))
} else {
domain.clone()
}
}
Self::Domain { value, .. } => value.clone(),
}
}
}