Skip to content

Commit 1edeb1d

Browse files
Clément VALENTINclaude
andcommitted
fix: normalize API base URL to prevent double slashes
Remove trailing slashes from VITE_API_BASE_URL before concatenating paths. This fixes issues where URLs like `http://localhost:8081/` would result in `http://localhost:8081//openapi.json`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 87016bc commit 1edeb1d

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

apps/web/src/pages/ApiDocs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ declare global {
1818
export default function ApiDocs() {
1919
const { isDark } = useThemeStore()
2020
// Use runtime config first, then build-time env, then default
21-
const apiBaseUrl = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
21+
// Remove trailing slash to avoid double slashes in URLs
22+
const rawApiBaseUrl = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
23+
const apiBaseUrl = rawApiBaseUrl.replace(/\/+$/, '')
2224

2325
useEffect(() => {
2426
// Hide the "Explore" link and customize Swagger UI colors

apps/web/src/pages/ConsentRedirect.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ declare global {
1212
}
1313

1414
// Use runtime config first, then build-time env, then default
15-
const API_BASE_URL = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
15+
// Remove trailing slash to avoid double slashes in URLs
16+
const rawApiBaseUrl = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
17+
const API_BASE_URL = rawApiBaseUrl.replace(/\/+$/, '')
1618

1719
export default function ConsentRedirect() {
1820
const [searchParams] = useSearchParams()

apps/web/src/pages/OAuthCallback.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ declare global {
1515
}
1616

1717
// Use runtime config first, then build-time env, then default
18-
const API_BASE_URL = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
18+
// Remove trailing slash to avoid double slashes in URLs
19+
const rawApiBaseUrl = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
20+
const API_BASE_URL = rawApiBaseUrl.replace(/\/+$/, '')
1921

2022
// Global flag to track redirect across component remounts (persists until page reload)
2123
declare global {

apps/web/src/pages/VerifyEmail.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
import { useEffect, useState } from 'react'
22
import { useNavigate, useSearchParams } from 'react-router-dom'
33

4+
// Runtime environment from env.js (generated at container startup)
5+
declare global {
6+
interface Window {
7+
__ENV__?: {
8+
VITE_API_BASE_URL?: string
9+
VITE_BACKEND_URL?: string
10+
}
11+
}
12+
}
13+
414
export default function VerifyEmail() {
515
const [searchParams] = useSearchParams()
616
const navigate = useNavigate()
717
const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading')
818
const [message, setMessage] = useState('')
919

10-
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000'
20+
// Use runtime config first, then build-time env, then default
21+
// Remove trailing slash to avoid double slashes in URLs
22+
const rawApiBaseUrl = window.__ENV__?.VITE_API_BASE_URL || import.meta.env.VITE_API_BASE_URL || '/api'
23+
const apiBaseUrl = rawApiBaseUrl.replace(/\/+$/, '')
1124

1225
useEffect(() => {
1326
const token = searchParams.get('token')

0 commit comments

Comments
 (0)