Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
42 lines
1.3 KiB
Plaintext
42 lines
1.3 KiB
Plaintext
import { parseStringToURLObject, isURLObjectRelative } from './url.js';
|
|
|
|
/**
|
|
* Checks whether given url points to Sentry server
|
|
*
|
|
* @param url url to verify
|
|
*/
|
|
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) {
|
|
// Requests to Sentry's ingest endpoint must have a `sentry_key` in the query string
|
|
// This is equivalent to the public_key which is required in the DSN
|
|
// see https://develop.sentry.dev/sdk/overview/#parsing-the-dsn
|
|
// Therefore, a request to the same host and with a `sentry_key` in the query string
|
|
// can be considered a request to the ingest endpoint.
|
|
const urlParts = parseStringToURLObject(url);
|
|
if (!urlParts || isURLObjectRelative(urlParts)) {
|
|
return false;
|
|
}
|
|
|
|
return dsn ? urlParts.host.includes(dsn.host) && /(^|&|\?)sentry_key=/.test(urlParts.search) : false;
|
|
}
|
|
|
|
function removeTrailingSlash(str) {
|
|
return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
|
|
}
|
|
|
|
export { isSentryRequestUrl };
|
|
//# sourceMappingURL=isSentryRequestUrl.js.map
|