Use next rewrites for API_URL.

This commit is contained in:
Mike Cao
2026-06-02 11:12:48 -07:00
parent 169387958e
commit f985b4f9a5
2 changed files with 22 additions and 11 deletions
+20 -11
View File
@@ -123,6 +123,7 @@ if (isProd) {
}
const rewrites = [];
const beforeFilesRewrites = [];
if (trackerScriptURL) {
rewrites.push({
@@ -157,6 +158,11 @@ if (isRelativeUrl(apiUrl)) {
destination: '/api/:path*',
});
}
} else if (apiUrl) {
beforeFilesRewrites.push({
source: '/api/:path((?!auth(?:/|$)|config(?:/|$)).*)',
destination: `${apiUrl.replace(/\/+$/, '')}/:path`,
});
}
const redirects = [
@@ -244,17 +250,20 @@ export default withNextIntl({
return headers;
},
async rewrites() {
return [
...rewrites,
{
source: '/telemetry.js',
destination: '/api/scripts/telemetry',
},
{
source: '/teams/:teamId/:path*',
destination: '/:path*',
},
];
return {
beforeFiles: beforeFilesRewrites,
afterFiles: [
...rewrites,
{
source: '/telemetry.js',
destination: '/api/scripts/telemetry',
},
{
source: '/teams/:teamId/:path*',
destination: '/:path*',
},
],
};
},
async redirects() {
return [...redirects];