39 lines
1010 B
TypeScript
39 lines
1010 B
TypeScript
import type { PublicDomainRoutingConfig } from "./CrossHostUrls";
|
|
import { isPublicWebRoutePath } from "./PublicRouteSegments";
|
|
|
|
type SurfaceInput = {
|
|
publicBaseUrl?: string;
|
|
serverUrl?: string;
|
|
routing?: PublicDomainRoutingConfig;
|
|
};
|
|
|
|
function hostFromUrl(value?: string) {
|
|
if (!value) {
|
|
return undefined;
|
|
}
|
|
try {
|
|
return new URL(value).host;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
function currentHost(input: SurfaceInput) {
|
|
return hostFromUrl(input.serverUrl) ?? hostFromUrl(input.publicBaseUrl);
|
|
}
|
|
|
|
export function isAdminSurface(input: SurfaceInput, pathname: string) {
|
|
return currentHost(input) === input.routing?.adminAppHost;
|
|
}
|
|
|
|
export function isAppSurface(input: SurfaceInput, pathname: string) {
|
|
if (isPublicWebRoutePath(pathname)) {
|
|
return false;
|
|
}
|
|
return currentHost(input) === input.routing?.webAppHost;
|
|
}
|
|
|
|
export function isAppOrAdminSurface(input: SurfaceInput, pathname: string) {
|
|
return isAppSurface(input, pathname) || isAdminSurface(input, pathname);
|
|
}
|