Build the org-scoped base URL. Given `url = "https://atomic.storage"` and `org = "alice"`, returns `"https://alice.atomic.storage"`. Given `url = "http://localhost:8080"` and `org = "alice"`, returns `"http://alice.localhost:8080"`. For single-tenant servers the org is already implied by the server itself, so the URL is returned unchanged (no `{org}.` prefix).
(&self, org_slug: &str)
| 136 | /// For single-tenant servers the org is already implied by the server |
| 137 | /// itself, so the URL is returned unchanged (no `{org}.` prefix). |
| 138 | pub fn org_base_url(&self, org_slug: &str) -> Option<String> { |
| 139 | let url = self.url.as_ref()?; |
| 140 | |
| 141 | // Single-tenant: the bare host is already tenant-scoped server-side; |
| 142 | // prefixing would produce bogus hosts like `org.org.org.example.com`. |
| 143 | if self.single_tenant { |
| 144 | return Some(url.trim_end_matches('/').to_string()); |
| 145 | } |
| 146 | |
| 147 | // Parse the URL to extract scheme, host, port |
| 148 | let url_parsed = url::Url::parse(url).ok()?; |
| 149 | let scheme = url_parsed.scheme(); |
| 150 | let host = url_parsed.host_str()?; |
| 151 | let port = url_parsed.port(); |
| 152 | |
| 153 | let base = if let Some(port) = port { |
| 154 | format!("{}://{}.{}:{}", scheme, org_slug, host, port) |
| 155 | } else { |
| 156 | format!("{}://{}.{}", scheme, org_slug, host) |
| 157 | }; |
| 158 | |
| 159 | Some(base) |
| 160 | } |
| 161 | |
| 162 | /// Get the org-scoped base URL using the default org. |
| 163 | pub fn default_org_base_url(&self) -> Option<String> { |
no test coverage detected