@@ -125,11 +125,7 @@ function getFinalConfigObject(
125125 const resolvedTunnelRoute = resolveTunnelRoute ( userSentryOptions . tunnelRoute ) ;
126126 userSentryOptions . tunnelRoute = resolvedTunnelRoute || undefined ;
127127
128- setUpTunnelRewriteRules (
129- incomingUserNextConfigObject ,
130- resolvedTunnelRoute ,
131- userSentryOptions . _tunnelRouteDestinationOverride ,
132- ) ;
128+ setUpTunnelRewriteRules ( incomingUserNextConfigObject , resolvedTunnelRoute ) ;
133129 }
134130 }
135131
@@ -393,12 +389,15 @@ function getFinalConfigObject(
393389 *
394390 * See https://nextjs.org/docs/api-reference/next.config.js/rewrites.
395391 */
396- function setUpTunnelRewriteRules (
397- userNextConfig : NextConfigObject ,
398- tunnelPath : string ,
399- destinationOverride ?: string ,
400- ) : void {
392+ function setUpTunnelRewriteRules ( userNextConfig : NextConfigObject , tunnelPath : string ) : void {
401393 const originalRewrites = userNextConfig . rewrites ;
394+ // Allow overriding the tunnel destination for E2E tests via environment variable
395+ const destinationOverride = process . env . _SENTRY_TUNNEL_DESTINATION_OVERRIDE ;
396+
397+ // Make sure destinations are statically defined at build time
398+ const destination = destinationOverride || 'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0' ;
399+ const destinationWithRegion =
400+ destinationOverride || 'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0' ;
402401
403402 // This function doesn't take any arguments at the time of writing but we future-proof
404403 // here in case Next.js ever decides to pass some
@@ -419,7 +418,7 @@ function setUpTunnelRewriteRules(
419418 value : '(?<projectid>\\d*)' ,
420419 } ,
421420 ] ,
422- destination : destinationOverride || 'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0' ,
421+ destination,
423422 } ;
424423
425424 const tunnelRouteRewriteWithRegion = {
@@ -443,7 +442,7 @@ function setUpTunnelRewriteRules(
443442 value : '(?<region>[a-z]{2})' ,
444443 } ,
445444 ] ,
446- destination : destinationOverride || 'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0' ,
445+ destination : destinationWithRegion ,
447446 } ;
448447
449448 // Order of these is important, they get applied first to last.
0 commit comments