Skip to content

Commit 8473dea

Browse files
committed
fix self-hosting auth issue with API_URL missing
1 parent a52f326 commit 8473dea

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ if (isRelativeUrl(apiUrl)) {
160160
}
161161
} else if (apiUrl) {
162162
beforeFilesRewrites.push({
163-
source: '/api/:path((?!auth(?:/|$)|config(?:/|$)).*)',
163+
source: '/api/:path((?!config(?:/|$)).*)',
164164
destination: `${apiUrl.replace(/\/+$/, '')}/:path`,
165165
});
166166
}

src/lib/api-url.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ describe('getApiUrl', () => {
2020
).toBe('/analytics/internal-api/websites');
2121
});
2222

23-
test('keeps app routes on the local api path', () => {
23+
test('uses a relative API_URL for auth routes', () => {
2424
expect(
2525
getApiUrl('/auth/verify', {
2626
apiUrl: '/internal-api',
2727
basePath: '/analytics',
2828
}),
29-
).toBe('/analytics/api/auth/verify');
29+
).toBe('/analytics/internal-api/auth/verify');
30+
});
31+
32+
test('keeps config routes on the local api path', () => {
33+
expect(
34+
getApiUrl('/config', {
35+
apiUrl: '/internal-api',
36+
basePath: '/analytics',
37+
}),
38+
).toBe('/analytics/api/config');
3039
});
3140

3241
test('returns absolute input urls unchanged', () => {

src/lib/api-url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type ApiUrlOptions = {
33
basePath?: string;
44
};
55

6-
const APP_ROUTE_PATTERNS: RegExp[] = [/^\/auth(\/|$)/, /^\/config(\/|$)/];
6+
const APP_ROUTE_PATTERNS: RegExp[] = [/^\/config(\/|$)/];
77

88
function trimTrailingSlash(value: string) {
99
return value.replace(/\/+$/, '');

0 commit comments

Comments
 (0)