From 0ce2822a764a081d907b2e9340138bd01e998536 Mon Sep 17 00:00:00 2001 From: VPS 4 Builder Date: Fri, 15 May 2026 08:31:51 +0200 Subject: [PATCH] =?UTF-8?q?fix(nginx):=20no-cache=20no=20index.html=20+=20?= =?UTF-8?q?immutable=20nos=20assets=20=E2=80=94=20evita=20vers=C3=A3o=20co?= =?UTF-8?q?ngelada=20no=20browser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Dockerfile | 11 ++++------- frontend/nginx.conf | 19 +++++++++++++++++++ nginx/default.conf | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 frontend/nginx.conf diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 23dba5e..437cbb5 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,17 +1,14 @@ -# Stage 1: Build Vite React App +# Stage 1: Build FROM node:20-alpine AS builder -WORKDIR /app -COPY update-version.js . -COPY frontend/package*.json frontend/ WORKDIR /app/frontend +COPY frontend/package*.json . RUN npm install COPY frontend/ . RUN npm run build -# Stage 2: Serve static files with high-performance Nginx on port 3013 +# Stage 2: Serve FROM nginx:alpine COPY --from=builder /app/frontend/dist /usr/share/nginx/html -# Simple internal Nginx routing for single-page React router stability -RUN echo 'server { listen 3013; location / { root /usr/share/nginx/html; index index.html; try_files $uri $uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf +COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 3013 CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..d5f7149 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 3013; + root /usr/share/nginx/html; + index index.html; + + # Assets com hash (Vite): cache imutável por 1 ano + location /assets/ { + add_header Cache-Control "public, max-age=31536000, immutable"; + try_files $uri =404; + } + + # index.html: nunca cachear — o browser sempre busca a versão mais recente + location / { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + add_header Expires "0"; + try_files $uri $uri/ /index.html; + } +} diff --git a/nginx/default.conf b/nginx/default.conf index 57051e0..5b6bdc1 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -36,7 +36,7 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } - # Proxy para o Frontend (Next.js SSR) + # Proxy para o Frontend (Vite React SPA) location / { set $frontend_upstream http://scoreodonto-frontend:3013; proxy_pass $frontend_upstream;