diff --git a/next.config.ts b/next.config.ts index 922d128bd..879b2d857 100644 --- a/next.config.ts +++ b/next.config.ts @@ -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]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed0e7f952..5c65e466d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -334,6 +334,8 @@ importers: specifier: ^4.1.6 version: 4.1.6(@types/node@25.9.0)(jsdom@29.1.1)(msw@2.14.6(@types/node@25.9.0)(typescript@6.0.3))(vite@8.0.11(@types/node@25.9.0)(esbuild@0.28.0)(jiti@2.7.0)(terser@5.46.1)(tsx@4.22.2)) + dist: {} + packages: '@adobe/css-tools@4.4.4':