diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh index a81272969..283e20a82 100644 --- a/docker/frontend/entrypoint.sh +++ b/docker/frontend/entrypoint.sh @@ -6,5 +6,13 @@ VITE_API_BASE_URL=${VITE_API_BASE_URL:-"http://backend:8080"} # Replace the placeholder in nginx.conf with the actual backend URL sed -i "s|\${VITE_API_BASE_URL}|${VITE_API_BASE_URL}|g" /etc/nginx/nginx.conf +# Inject runtime configuration into config.js +cat > /usr/share/nginx/html/config.js << EOF +// Runtime configuration - injected at container startup +window.runtimeConfig = { + apiBaseUrl: '${VITE_API_BASE_URL}' +}; +EOF + # Start nginx exec nginx -g "daemon off;" \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index 0fc165c66..964c2d4b8 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -12,11 +12,12 @@ - Vite App + Stirling-PDF
+ diff --git a/frontend/public/config.js b/frontend/public/config.js new file mode 100644 index 000000000..b3c3d1615 --- /dev/null +++ b/frontend/public/config.js @@ -0,0 +1,4 @@ +// Runtime configuration - injected at container startup +window.runtimeConfig = { + apiBaseUrl: 'http://localhost:8080' +}; \ No newline at end of file diff --git a/frontend/src/utils/api.ts b/frontend/src/utils/api.ts index 3038dbb14..b2c6fd65f 100644 --- a/frontend/src/utils/api.ts +++ b/frontend/src/utils/api.ts @@ -1,14 +1,14 @@ -const apiBaseUrl = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080'; - +// Runtime configuration access +declare global { + interface Window { + runtimeConfig?: { + apiBaseUrl?: string; + }; + } +} export const makeApiUrl = (endpoint: string): string => { - const baseUrl = apiBaseUrl; - - // If baseUrl is empty (development), return endpoint as-is for proxy - if (!baseUrl) { - return endpoint; - } - + const baseUrl = window.runtimeConfig?.apiBaseUrl || 'http://localhost:8080'; // For production, combine base URL with endpoint return `${baseUrl}${endpoint}`; }; \ No newline at end of file