Merge branch 'analytics' into dev
This commit is contained in:
@@ -47,7 +47,7 @@ DATABASE_URL=connection-url
|
||||
```
|
||||
|
||||
Optional: set `API_URL` to change the base URL used by internal UI API calls.
|
||||
Relative paths are served under `BASE_PATH`; absolute URLs are called directly by the browser.
|
||||
Relative paths are served under `BASE_PATH`; absolute URLs are proxied through the local `/api` route.
|
||||
For example, `API_URL=/internal-api` or `API_URL=https://api.example.com/api`.
|
||||
|
||||
The connection URL format:
|
||||
|
||||
+11
-2
@@ -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,7 +250,9 @@ export default withNextIntl({
|
||||
return headers;
|
||||
},
|
||||
async rewrites() {
|
||||
return [
|
||||
return {
|
||||
beforeFiles: beforeFilesRewrites,
|
||||
afterFiles: [
|
||||
...rewrites,
|
||||
{
|
||||
source: '/telemetry.js',
|
||||
@@ -254,7 +262,8 @@ export default withNextIntl({
|
||||
source: '/teams/:teamId/:path*',
|
||||
destination: '/:path*',
|
||||
},
|
||||
];
|
||||
],
|
||||
};
|
||||
},
|
||||
async redirects() {
|
||||
return [...redirects];
|
||||
|
||||
Generated
+2
@@ -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':
|
||||
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user