Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Revert to external API url.

Mike Cao7de662a71ed8
diff --git a/next.config.ts b/next.config.ts
index 879b2d857..922d128bd 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -123,7 +123,6 @@ if (isProd) {
}
const rewrites = [];
-const beforeFilesRewrites = [];
if (trackerScriptURL) {
rewrites.push({
@@ -158,11 +157,6 @@ if (isRelativeUrl(apiUrl)) {
destination: '/api/:path*',
});
}
-} else if (apiUrl) {
- beforeFilesRewrites.push({
- source: '/api/:path((?!auth(?:/|$)|config(?:/|$)).*)',
- destination: `${apiUrl.replace(/\/+$/, '')}/:path`,
- });
}
const redirects = [
@@ -250,20 +244,17 @@ export default withNextIntl({
return headers;
},
async rewrites() {
- return {
- beforeFiles: beforeFilesRewrites,
- afterFiles: [
- ...rewrites,
- {
- source: '/telemetry.js',
- destination: '/api/scripts/telemetry',
- },
- {
- source: '/teams/:teamId/:path*',
- destination: '/:path*',
- },
- ],
- };
+ return [
+ ...rewrites,
+ {
+ source: '/telemetry.js',
+ destination: '/api/scripts/telemetry',
+ },
+ {
+ source: '/teams/:teamId/:path*',
+ destination: '/:path*',
+ },
+ ];
},
async redirects() {
return [...redirects];
diff --git a/src/lib/api-url.test.ts b/src/lib/api-url.test.ts
index 322315b00..9aae49161 100644
--- a/src/lib/api-url.test.ts
+++ b/src/lib/api-url.test.ts
@@ -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', () => {
diff --git a/src/lib/api-url.ts b/src/lib/api-url.ts
index 8cc790c1b..104634fde 100644
--- a/src/lib/api-url.ts
+++ b/src/lib/api-url.ts
@@ -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);
}