release: WRNexusJS 0.5.10
This commit is contained in:
@@ -56,3 +56,26 @@ export function currentAppOrigin(): string | undefined {
|
||||
export function workspaceAppOrigins(): Readonly<Record<string, string>> {
|
||||
return Object.freeze({ ...workspaceOrigins() });
|
||||
}
|
||||
|
||||
/** Shared DNS suffix for configured workspace apps (for example `staging.example.com`). */
|
||||
export function workspaceRootDomain(): string {
|
||||
const hosts = Object.values(workspaceOrigins()).map((origin) =>
|
||||
new URL(origin).hostname.toLowerCase(),
|
||||
);
|
||||
if (!hosts.length) {
|
||||
throw new Error("Workspace origins are unavailable.");
|
||||
}
|
||||
|
||||
const labels = hosts.map((host) => host.split(".").reverse());
|
||||
const common: string[] = [];
|
||||
for (let index = 0; index < labels[0]!.length; index++) {
|
||||
const label = labels[0]![index];
|
||||
if (!labels.every((parts) => parts[index] === label)) break;
|
||||
common.push(label!);
|
||||
}
|
||||
|
||||
if (!common.length) {
|
||||
throw new Error(`Workspace apps do not share a root domain: ${hosts.join(", ")}.`);
|
||||
}
|
||||
return common.reverse().join(".");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user