release: WRNexusJS 0.2.29
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
function workspaceOrigins(): Record<string, string> {
|
||||
const value = process.env.WRNEXUS_WORKSPACE_ORIGINS;
|
||||
|
||||
if (!value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return parsed as Record<string, string>;
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function normalizePath(path: string): string {
|
||||
if (!path) return "/";
|
||||
|
||||
return path.startsWith("/") ? path : `/${path}`;
|
||||
}
|
||||
|
||||
export function appOrigin(appName: string): string {
|
||||
const origins = workspaceOrigins();
|
||||
const origin = origins[appName];
|
||||
|
||||
if (!origin) {
|
||||
throw new Error(
|
||||
`Unknown workspace app "${appName}". Available apps: ${
|
||||
Object.keys(origins).join(", ") || "none"
|
||||
}.`,
|
||||
);
|
||||
}
|
||||
|
||||
return new URL(origin).origin;
|
||||
}
|
||||
|
||||
export function appUrl(appName: string, path = "/"): string {
|
||||
return new URL(normalizePath(path), `${appOrigin(appName)}/`).href;
|
||||
}
|
||||
|
||||
export function currentAppName(): string | undefined {
|
||||
return process.env.WRNEXUS_APP_NAME;
|
||||
}
|
||||
|
||||
export function currentAppOrigin(): string | undefined {
|
||||
const value = process.env.WRNEXUS_APP_ORIGIN;
|
||||
|
||||
return value ? new URL(value).origin : undefined;
|
||||
}
|
||||
|
||||
export function workspaceAppOrigins(): Readonly<Record<string, string>> {
|
||||
return Object.freeze({ ...workspaceOrigins() });
|
||||
}
|
||||
Reference in New Issue
Block a user