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).
|
# 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).
|
# Đổ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_APP_NAME=danable
|
||||||
ARG VITE_USE_MOCK_DATA=true
|
ARG VITE_USE_MOCK_DATA=true
|
||||||
ENV VITE_API_URL=$VITE_API_URL \
|
ENV VITE_API_URL=$VITE_API_URL \
|
||||||
|
|
@ -21,7 +21,7 @@ RUN npm run build
|
||||||
# ---- stage 2: serve tĩnh bằng nginx ----
|
# ---- stage 2: serve tĩnh bằng nginx ----
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
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.)
|
# ($$ trong Dockerfile -> $ trong file config.)
|
||||||
RUN printf '%s\n' \
|
RUN printf '%s\n' \
|
||||||
'server {' \
|
'server {' \
|
||||||
|
|
@ -29,6 +29,12 @@ RUN printf '%s\n' \
|
||||||
' server_name _;' \
|
' server_name _;' \
|
||||||
' root /usr/share/nginx/html;' \
|
' root /usr/share/nginx/html;' \
|
||||||
' index index.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 / {' \
|
' location / {' \
|
||||||
' try_files $uri $uri/ /index.html;' \
|
' try_files $uri $uri/ /index.html;' \
|
||||||
' }' \
|
' }' \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue