Files
2024-02-15 17:01:50 +00:00

31 lines
879 B
TypeScript

type ExtractedSlug = {
domain: string;
slug: string;
};
// XXX: If you change this also change its sibiling in:
// - static/index.ejs
// - webpack.config.ts
const KNOWN_DOMAINS = /(?:\.?)((?:localhost|dev\.getsentry\.net|sentry\.dev)(?:\:\d*)?)$/;
/**
* Extract a slug from a known local development host.
* If the host is not a known development host null is returned.
*/
export function extractSlug(hostname: string): ExtractedSlug | null {
const match = hostname.match(KNOWN_DOMAINS);
if (!match) {
return null;
}
const [
matchedExpression, // Expression includes optional leading `.`
matchedDomain, // First match group never includes optional leading `.`
] = match;
const [slug, ...domainParts] = hostname.replace(matchedExpression, '').split('.');
const domain = domainParts.concat(matchedDomain).join('.');
return {slug, domain};
}