Revert to external API url.
This commit is contained in:
1 parent
9ced9ac85a
commit
7de662a71e
3 files changed
+28
-24
No files matched your search
+11
-2
@@ -2,13 +2,22 @@ import { describe, expect, test } from 'vitest';
|
||||
import { getApiUrl } from './api-url';
|
||||
|
||||
describe('getApiUrl', () => {
|
||||
test('uses the local api path when API_URL is absolute', () => {
|
||||
test('calls an absolute API_URL directly', () => {
|
||||
expect(
|
||||
getApiUrl('/websites', {
|
||||
apiUrl: 'https://gateway-eu.umami.dev/api',
|
||||
basePath: '/analytics',
|
||||
}),
|
||||
).toBe('/analytics/api/websites');
|
||||
).toBe('https://gateway-eu.umami.dev/api/websites');
|
||||
});
|
||||
|
||||
test('keeps app routes on the local api path when API_URL is absolute', () => {
|
||||
expect(
|
||||
getApiUrl('/auth/verify', {
|
||||
apiUrl: 'https://gateway-eu.umami.dev/api',
|
||||
basePath: '/analytics',
|
||||
}),
|
||||
).toBe('/analytics/api/auth/verify');
|
||||
});
|
||||
|
||||
test('uses a relative API_URL under the base path', () => {
|
||||
|
||||
+6
-2
@@ -39,8 +39,12 @@ export function getApiUrl(url: string, options: ApiUrlOptions = {}) {
|
||||
}
|
||||
|
||||
const { apiUrl = process.env.apiUrl || '', basePath = process.env.basePath || '' } = options;
|
||||
const useApiUrl = apiUrl && !isAbsoluteUrl(apiUrl) && !isAppRoute(url);
|
||||
const baseUrl = useApiUrl ? joinPath(basePath, apiUrl) : joinPath(basePath, '/api');
|
||||
const useApiUrl = apiUrl && !isAppRoute(url);
|
||||
const baseUrl = useApiUrl
|
||||
? isAbsoluteUrl(apiUrl)
|
||||
? apiUrl
|
||||
: joinPath(basePath, apiUrl)
|
||||
: joinPath(basePath, '/api');
|
||||
|
||||
return joinPath(baseUrl, url);
|
||||
}
|
||||
Reference in new issue
Block a user