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;