* change the api of domain parsing to just parseDomain and getCookieDomain * adds getBaseDomain as the method to get the domain after any official subdomains
35 lines
917 B
TypeScript
35 lines
917 B
TypeScript
import env from "../env";
|
|
import { parseDomain } from "./domains";
|
|
|
|
export function cdnPath(path: string): string {
|
|
return `${env.CDN_URL}${path}`;
|
|
}
|
|
|
|
// TODO: HACK: if this is called server-side, it will always return false.
|
|
// - The only call sites to this function and isExternalUrl are on the client
|
|
// - The reason this is in a shared util is because it's used in an editor plugin
|
|
// which is also in the shared code
|
|
export function isInternalUrl(href: string) {
|
|
// empty strings are never internal
|
|
if (href === "") {
|
|
return false;
|
|
}
|
|
|
|
// relative paths are always internal
|
|
if (href[0] === "/") {
|
|
return true;
|
|
}
|
|
|
|
const outline =
|
|
typeof window !== "undefined"
|
|
? parseDomain(window.location.href)
|
|
: undefined;
|
|
|
|
const domain = parseDomain(href);
|
|
return outline?.host === domain.host;
|
|
}
|
|
|
|
export function isExternalUrl(href: string) {
|
|
return !isInternalUrl(href);
|
|
}
|