Merge branch 'analytics' into dev

This commit is contained in:
Mike Cao committed 2026-06-02 20:22:32 -07:00
commit 0f36990040
5 files changed
+62 -18

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, test } from 'vitest';
import { getApiUrl } from './api-url';
describe('getApiUrl', () => {
test('uses the local api path when API_URL is absolute', () => {
expect(
getApiUrl('/websites', {
apiUrl: 'https://gateway-eu.umami.dev/api',
basePath: '/analytics',
}),
).toBe('/analytics/api/websites');
});
test('uses a relative API_URL under the base path', () => {
expect(
getApiUrl('/websites', {
apiUrl: '/internal-api',
basePath: '/analytics',
}),
).toBe('/analytics/internal-api/websites');
});
test('keeps app routes on the local api path', () => {
expect(
getApiUrl('/auth/verify', {
apiUrl: '/internal-api',
basePath: '/analytics',
}),
).toBe('/analytics/api/auth/verify');
});
test('returns absolute input urls unchanged', () => {
expect(getApiUrl('https://example.com/api/websites')).toBe(
'https://example.com/api/websites',
);
});
});
+2 -6
View File
@@ -39,12 +39,8 @@ export function getApiUrl(url: string, options: ApiUrlOptions = {}) {
}
const { apiUrl = process.env.apiUrl || '', basePath = process.env.basePath || '' } = options;
const useApiUrl = apiUrl && !isAppRoute(url);
const baseUrl = useApiUrl
? isAbsoluteUrl(apiUrl)
? apiUrl
: joinPath(basePath, apiUrl)
: joinPath(basePath, '/api');
const useApiUrl = apiUrl && !isAbsoluteUrl(apiUrl) && !isAppRoute(url);
const baseUrl = useApiUrl ? joinPath(basePath, apiUrl) : joinPath(basePath, '/api');
return joinPath(baseUrl, url);
}