fix(admin-ui): derive the apex and subdomain style from the admin host

The admin SPA special-cased one deployment's hostnames to choose between
dot (img.<apex>) and hyphen (img-<apex>) subdomains. The server always
mounts the SPA on its own admin subdomain, so read both from that:
admin.<apex> means dot style, admin-<apex> hyphen style.
This commit is contained in:
Alexa
2026-10-25 14:42:10 +02:00
parent 12da61407d
commit 260f6605fc
+18 -11
View File
@@ -49,21 +49,28 @@ export function assetCdnUrl(path: string | null | undefined): string | null {
return subdomainUrl('cdn', path, undefined, true); return subdomainUrl('cdn', path, undefined, true);
} }
export function adminApex(): string { // The server mounts this SPA on its own `admin` subdomain, so the admin
if (typeof window === 'undefined') return 'rec.net'; // host tells us the deployment's apex and subdomain style: `admin.<apex>`
// (dot style, `img.<apex>`) or `admin-<apex>` (hyphen style, `img-<apex>`).
function adminHost(): { apex: string; hyphen: boolean } {
if (typeof window === 'undefined') return { apex: 'rec.net', hyphen: false };
const host = window.location.hostname.toLowerCase(); const host = window.location.hostname.toLowerCase();
if (host === 'localhost' || host.endsWith('.localhost')) return 'localhost'; if (host === 'localhost' || host.endsWith('.localhost')) return { apex: 'localhost', hyphen: false };
if (host.endsWith('-dev.example.com')) return 'dev.example.com';
const parts = host.split('.'); const [first, ...rest] = host.split('.');
return parts.length > 2 ? parts.slice(1).join('.') : host; if (first.startsWith('admin-') && rest.length > 0)
return { apex: [first.slice('admin-'.length), ...rest].join('.'), hyphen: true };
return { apex: rest.length >= 2 ? rest.join('.') : host, hyphen: false };
} }
function serviceHost(subdomain: string, apex: string): string { export function adminApex(): string {
return apex === 'dev.example.com' return adminHost().apex;
? `${subdomain}-${apex}` }
: `${subdomain}.${apex}`;
function serviceHost(subdomain: string): string {
const { apex, hyphen } = adminHost();
return hyphen ? `${subdomain}-${apex}` : `${subdomain}.${apex}`;
} }
function subdomainUrl(subdomain: string, path: string | null | undefined, query?: string, preserveSlashes = false): string | null { function subdomainUrl(subdomain: string, path: string | null | undefined, query?: string, preserveSlashes = false): string | null {
@@ -74,7 +81,7 @@ function subdomainUrl(subdomain: string, path: string | null | undefined, query?
const encodedPath = preserveSlashes const encodedPath = preserveSlashes
? path.split('/').map(encodeURIComponent).join('/') ? path.split('/').map(encodeURIComponent).join('/')
: encodeURIComponent(path); : encodeURIComponent(path);
return `${scheme}://${serviceHost(subdomain, apex)}/${encodedPath}${suffix}`; return `${scheme}://${serviceHost(subdomain)}/${encodedPath}${suffix}`;
} }
export interface Room { export interface Room {