stack/apps/dashboard/src/lib/utils.tsx
Zai Shi 54027d58a2
New client (#135)
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2024-07-19 22:07:44 -07:00

24 lines
854 B
TypeScript

import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { DomainConfigJson } from "@/temporary-types";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
// TODO next-release: remove
export function validateUrl(url: string, domains: DomainConfigJson[], allowLocalhost: boolean): boolean {
if (allowLocalhost && (new URL(url).hostname === "localhost" || new URL(url).hostname.match(/^127\.\d+\.\d+\.\d+$/))) {
return true;
}
return domains.some((domain) => {
const testUrl = new URL(url);
const baseUrl = new URL(domain.handlerPath, domain.domain);
const sameOrigin = baseUrl.protocol === testUrl.protocol && baseUrl.hostname === testUrl.hostname;
const isSubPath = testUrl.pathname.startsWith(baseUrl.pathname);
return sameOrigin && isSubPath;
});
}