tunnelRoute.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const utils = require('@sentry/utils');
  3. const debugBuild = require('../common/debug-build.js');
  4. const globalWithInjectedValues = global
  5. ;
  6. /**
  7. * Applies the `tunnel` option to the Next.js SDK options based on `withSentryConfig`'s `tunnelRoute` option.
  8. */
  9. function applyTunnelRouteOption(options) {
  10. const tunnelRouteOption = globalWithInjectedValues.__sentryRewritesTunnelPath__;
  11. if (tunnelRouteOption && options.dsn) {
  12. const dsnComponents = utils.dsnFromString(options.dsn);
  13. if (!dsnComponents) {
  14. return;
  15. }
  16. const sentrySaasDsnMatch = dsnComponents.host.match(/^o(\d+)\.ingest\.sentry\.io$/);
  17. if (sentrySaasDsnMatch) {
  18. const orgId = sentrySaasDsnMatch[1];
  19. const tunnelPath = `${tunnelRouteOption}?o=${orgId}&p=${dsnComponents.projectId}`;
  20. options.tunnel = tunnelPath;
  21. debugBuild.DEBUG_BUILD && utils.logger.info(`Tunneling events to "${tunnelPath}"`);
  22. } else {
  23. debugBuild.DEBUG_BUILD && utils.logger.warn('Provided DSN is not a Sentry SaaS DSN. Will not tunnel events.');
  24. }
  25. }
  26. }
  27. exports.applyTunnelRouteOption = applyTunnelRouteOption;
  28. //# sourceMappingURL=tunnelRoute.js.map