Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs/v7): Fix tunnelRoute matching logic for hybrid cloud #11577

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/nextjs/src/config/withSentryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,28 @@ function setUpTunnelRewriteRules(userNextConfig: NextConfigObject, tunnelPath: s
{
type: 'query',
key: 'r', // short for region - we keep it short so matching is harder for ad-blockers
value: '(?<region>\\[a-z\\]{2})',
value: '(?<region>[a-z]{2})',
},
],
destination: 'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0',
};

// Order of these is important, they get applied first to last.
const newRewrites = [tunnelRouteRewriteWithRegion, tunnelRouteRewrite];

if (typeof originalRewrites !== 'function') {
return [tunnelRouteRewriteWithRegion, tunnelRouteRewrite];
return newRewrites;
}

// @ts-expect-error Expected 0 arguments but got 1 - this is from the future-proofing mentioned above, so we don't care about it
const originalRewritesResult = await originalRewrites(...args);

if (Array.isArray(originalRewritesResult)) {
return [tunnelRouteRewriteWithRegion, tunnelRouteRewrite, ...originalRewritesResult];
return [...newRewrites, ...originalRewritesResult];
} else {
return {
...originalRewritesResult,
beforeFiles: [tunnelRouteRewriteWithRegion, tunnelRouteRewrite, ...(originalRewritesResult.beforeFiles || [])],
beforeFiles: [...newRewrites, ...(originalRewritesResult.beforeFiles || [])],
};
}
};
Expand Down