fix: pass Vite env vars as Docker build args
Vite reads env vars at build time, not runtime. The previous setup only set them in docker-compose 'environment' which is only available at container runtime. Now they are passed as build args so Vite can embed the correct API URL during the build process. - Add build args to web service in both compose files - Update Dockerfile to accept ARGs and set ENV for Vite - Fixes login redirect always going to localhost:8000
This commit is contained in:
@@ -12,6 +12,12 @@ RUN npm install
|
|||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Accept build arguments for API and app URLs
|
||||||
|
ARG VITE_API_BASE_URL
|
||||||
|
ARG VITE_APP_URL
|
||||||
|
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
|
||||||
|
ENV VITE_APP_URL=${VITE_APP_URL}
|
||||||
|
|
||||||
# Build production bundle
|
# Build production bundle
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./apps/web
|
context: ./apps/web
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
VITE_API_BASE_URL: ${API_PUBLIC_URL:-https://${API_DOMAIN}}
|
||||||
|
VITE_APP_URL: ${WEB_PUBLIC_URL:-https://${WEB_DOMAIN}}
|
||||||
container_name: hq-web
|
container_name: hq-web
|
||||||
environment:
|
environment:
|
||||||
VITE_API_BASE_URL: ${API_PUBLIC_URL:-https://${API_DOMAIN}}
|
VITE_API_BASE_URL: ${API_PUBLIC_URL:-https://${API_DOMAIN}}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./apps/web
|
context: ./apps/web
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
VITE_API_BASE_URL: http://localhost:8000
|
||||||
container_name: hq-web
|
container_name: hq-web
|
||||||
environment:
|
environment:
|
||||||
VITE_API_BASE_URL: http://localhost:8000
|
VITE_API_BASE_URL: http://localhost:8000
|
||||||
|
|||||||
Reference in New Issue
Block a user