Fix production auth by proxying /api to backend in remote builds.

Remote frontend nginx now forwards API requests to Django so login and registration work when the host proxy only routes to port 8080.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gitrusprus
2026-06-29 09:33:54 +03:00
co-authored by Cursor
parent ce4e9ac5e6
commit 10e7d65a00
6 changed files with 70 additions and 13 deletions
+8 -1
View File
@@ -16,7 +16,14 @@ RUN npm run build
FROM nginx:1.27-alpine AS runtime
COPY nginx.conf /etc/nginx/conf.d/default.conf
ARG VITE_DATA_MODE=local
COPY nginx.conf /tmp/nginx.local.conf
COPY nginx.remote.conf /tmp/nginx.remote.conf
RUN if [ "$VITE_DATA_MODE" = "remote" ]; then \
cp /tmp/nginx.remote.conf /etc/nginx/conf.d/default.conf; \
else \
cp /tmp/nginx.local.conf /etc/nginx/conf.d/default.conf; \
fi
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
+32
View File
@@ -0,0 +1,32 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
# API → Django backend (контейнер backend в docker-compose)
location /api/ {
proxy_pass http://backend:8000/api/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 10s;
proxy_read_timeout 120s;
}
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
expires 7d;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
}
+9 -1
View File
@@ -1,6 +1,14 @@
export function formatApiErrorData(data) {
if (!data) return ''
if (typeof data === 'string' && data.trim()) return data.trim()
if (typeof data === 'string' && data.trim()) {
const text = data.trim()
if (text.startsWith('<') && text.includes('</html>')) {
const title = text.match(/<title>([^<]+)<\/title>/i)?.[1]?.trim()
if (title) return title
return 'Сервер вернул HTML вместо JSON. Проверьте проксирование /api на backend.'
}
return text
}
if (typeof data?.detail === 'string' && data.detail.trim()) return data.detail.trim()
if (Array.isArray(data?.non_field_errors) && data.non_field_errors.length) {
return data.non_field_errors.join('; ')