isSentryRequestUrl.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Checks whether given url points to Sentry server
  3. * @param url url to verify
  4. *
  5. * TODO(v8): Remove Hub fallback type
  6. */
  7. function isSentryRequestUrl(url, hubOrClient) {
  8. const client =
  9. hubOrClient && isHub(hubOrClient)
  10. ? // eslint-disable-next-line deprecation/deprecation
  11. hubOrClient.getClient()
  12. : hubOrClient;
  13. const dsn = client && client.getDsn();
  14. const tunnel = client && client.getOptions().tunnel;
  15. return checkDsn(url, dsn) || checkTunnel(url, tunnel);
  16. }
  17. function checkTunnel(url, tunnel) {
  18. if (!tunnel) {
  19. return false;
  20. }
  21. return removeTrailingSlash(url) === removeTrailingSlash(tunnel);
  22. }
  23. function checkDsn(url, dsn) {
  24. return dsn ? url.includes(dsn.host) : false;
  25. }
  26. function removeTrailingSlash(str) {
  27. return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
  28. }
  29. function isHub(hubOrClient) {
  30. // eslint-disable-next-line deprecation/deprecation
  31. return (hubOrClient ).getClient !== undefined;
  32. }
  33. export { isSentryRequestUrl };
  34. //# sourceMappingURL=isSentryRequestUrl.js.map