@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
33 lines (30 loc) • 1.02 kB
JavaScript
import { parseStringToURLObject, isURLObjectRelative } from './url.js';
function isSentryRequestUrl(url, client) {
const dsn = client?.getDsn();
const tunnel = client?.getOptions().tunnel;
return checkDsn(url, dsn) || checkTunnel(url, tunnel);
}
function checkTunnel(url, tunnel) {
if (!tunnel) {
return false;
}
return removeTrailingSlash(url) === removeTrailingSlash(tunnel);
}
function checkDsn(url, dsn) {
const urlParts = parseStringToURLObject(url);
if (!urlParts || isURLObjectRelative(urlParts)) {
return false;
}
if (!dsn) {
return false;
}
return hostnameMatchesDsnHost(urlParts.hostname, dsn.host) && /(^|&|\?)sentry_key=/.test(urlParts.search);
}
function hostnameMatchesDsnHost(hostname, dsnHost) {
return hostname === dsnHost || dsnHost.length > 0 && hostname.endsWith(`.${dsnHost}`);
}
function removeTrailingSlash(str) {
return str[str.length - 1] === "/" ? str.slice(0, -1) : str;
}
export { isSentryRequestUrl };
//# sourceMappingURL=isSentryRequestUrl.js.map