Skip to content

Commit de487e5

Browse files
committed
Merge branch 'analytics' into dev
2 parents 4956380 + 7de662a commit de487e5

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

next.config.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ if (isProd) {
123123
}
124124

125125
const rewrites = [];
126-
const beforeFilesRewrites = [];
127126

128127
if (trackerScriptURL) {
129128
rewrites.push({
@@ -158,11 +157,6 @@ if (isRelativeUrl(apiUrl)) {
158157
destination: '/api/:path*',
159158
});
160159
}
161-
} else if (apiUrl) {
162-
beforeFilesRewrites.push({
163-
source: '/api/:path((?!auth(?:/|$)|config(?:/|$)).*)',
164-
destination: `${apiUrl.replace(/\/+$/, '')}/:path`,
165-
});
166160
}
167161

168162
const redirects = [
@@ -250,20 +244,17 @@ export default withNextIntl({
250244
return headers;
251245
},
252246
async rewrites() {
253-
return {
254-
beforeFiles: beforeFilesRewrites,
255-
afterFiles: [
256-
...rewrites,
257-
{
258-
source: '/telemetry.js',
259-
destination: '/api/scripts/telemetry',
260-
},
261-
{
262-
source: '/teams/:teamId/:path*',
263-
destination: '/:path*',
264-
},
265-
],
266-
};
247+
return [
248+
...rewrites,
249+
{
250+
source: '/telemetry.js',
251+
destination: '/api/scripts/telemetry',
252+
},
253+
{
254+
source: '/teams/:teamId/:path*',
255+
destination: '/:path*',
256+
},
257+
];
267258
},
268259
async redirects() {
269260
return [...redirects];

src/lib/api-url.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ import { describe, expect, test } from 'vitest';
22
import { getApiUrl } from './api-url';
33

44
describe('getApiUrl', () => {
5-
test('uses the local api path when API_URL is absolute', () => {
5+
test('calls an absolute API_URL directly', () => {
66
expect(
77
getApiUrl('/websites', {
88
apiUrl: 'https://gateway-eu.umami.dev/api',
99
basePath: '/analytics',
1010
}),
11-
).toBe('/analytics/api/websites');
11+
).toBe('https://gateway-eu.umami.dev/api/websites');
12+
});
13+
14+
test('keeps app routes on the local api path when API_URL is absolute', () => {
15+
expect(
16+
getApiUrl('/auth/verify', {
17+
apiUrl: 'https://gateway-eu.umami.dev/api',
18+
basePath: '/analytics',
19+
}),
20+
).toBe('/analytics/api/auth/verify');
1221
});
1322

1423
test('uses a relative API_URL under the base path', () => {

src/lib/api-url.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ export function getApiUrl(url: string, options: ApiUrlOptions = {}) {
3636
}
3737

3838
const { apiUrl = process.env.apiUrl || '', basePath = process.env.basePath || '' } = options;
39-
const useApiUrl = apiUrl && !isAbsoluteUrl(apiUrl) && !isAppRoute(url);
40-
const baseUrl = useApiUrl ? joinPath(basePath, apiUrl) : joinPath(basePath, '/api');
39+
const useApiUrl = apiUrl && !isAppRoute(url);
40+
const baseUrl = useApiUrl
41+
? isAbsoluteUrl(apiUrl)
42+
? apiUrl
43+
: joinPath(basePath, apiUrl)
44+
: joinPath(basePath, '/api');
4145

4246
return joinPath(baseUrl, url);
4347
}

0 commit comments

Comments
 (0)