fix: proxy production API through frontend
This commit is contained in:
parent
b0912d0b21
commit
30c176733d
1 changed files with 8 additions and 2 deletions
10
Dockerfile
10
Dockerfile
|
|
@ -4,7 +4,7 @@ WORKDIR /app
|
|||
|
||||
# Biến môi trường Vite (đọc từ .env trên prod lúc compose build).
|
||||
# Đổi API URL -> build lại là nhận (compose up --build tự làm).
|
||||
ARG VITE_API_URL=http://localhost:8000/api/v1
|
||||
ARG VITE_API_URL=/api/v1
|
||||
ARG VITE_APP_NAME=danable
|
||||
ARG VITE_USE_MOCK_DATA=true
|
||||
ENV VITE_API_URL=$VITE_API_URL \
|
||||
|
|
@ -21,7 +21,7 @@ RUN npm run build
|
|||
# ---- stage 2: serve tĩnh bằng nginx ----
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
# Ghi đè default conf: SPA fallback + cache lâu cho /assets.
|
||||
# Ghi đè default conf: same-origin API proxy, SPA fallback + cache lâu cho /assets.
|
||||
# ($$ trong Dockerfile -> $ trong file config.)
|
||||
RUN printf '%s\n' \
|
||||
'server {' \
|
||||
|
|
@ -29,6 +29,12 @@ RUN printf '%s\n' \
|
|||
' server_name _;' \
|
||||
' root /usr/share/nginx/html;' \
|
||||
' index index.html;' \
|
||||
' location /api/ {' \
|
||||
' proxy_pass http://be:8000;' \
|
||||
' proxy_set_header Host $host;' \
|
||||
' proxy_set_header X-Real-IP $remote_addr;' \
|
||||
' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' \
|
||||
' }' \
|
||||
' location / {' \
|
||||
' try_files $uri $uri/ /index.html;' \
|
||||
' }' \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue