Last active
June 11, 2024 06:42
-
-
Save mozeryansky/269bf92676b072e9974a7982833b2d93 to your computer and use it in GitHub Desktop.
Next.js full url redirect for Sentry and PostHog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// next.config.js | |
const nextConfig = { | |
async rewrites() { | |
return [ | |
// Sentry | |
{ | |
source: '/sentry(/?)', | |
has: [ | |
{ | |
type: 'query', | |
key: 'o', | |
value: '(?<orgid>\\d*)', | |
}, | |
{ | |
type: 'query', | |
key: 'p', | |
value: '(?<projectid>\\d*)', | |
}, | |
{ | |
type: 'query', | |
key: 'r', | |
value: '(?<region>[a-z]{2})', | |
}, | |
], | |
destination: | |
'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0', | |
}, | |
{ | |
source: '/sentry(/?)', | |
has: [ | |
{ | |
type: 'query', | |
key: 'o', | |
value: '(?<orgid>\\d*)', | |
}, | |
{ | |
type: 'query', | |
key: 'p', | |
value: '(?<projectid>\\d*)', | |
}, | |
], | |
destination: | |
'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0', | |
}, | |
// PostHog | |
{ | |
source: '/posthog/static/:path*', | |
destination: 'https://us-assets.i.posthog.com/static/:path*', | |
}, | |
{ | |
source: '/posthog/:path*', | |
destination: 'https://us.i.posthog.com/:path*', | |
}, | |
] | |
}, | |
// This is required to support PostHog trailing slash API requests | |
skipTrailingSlashRedirect: true, | |
} | |
module.exports = nextConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the main website:
And use the next config in example.com
getsentry/sentry-javascript#12447