From 9abc1e38887e65bd380a0a4ed4930836e4c685a5 Mon Sep 17 00:00:00 2001 From: Egor Pozharov Date: Tue, 14 Apr 2026 17:30:43 +0600 Subject: [PATCH] add /api proxy --- frontend/.env.example | 4 +++- frontend/nginx.conf | 13 +++++++++++++ frontend/src/api/client.ts | 2 +- frontend/vite.config.ts | 6 ++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/.env.example b/frontend/.env.example index 9db8f88..4ba1803 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,2 +1,4 @@ # API Configuration -VITE_API_URL=http://localhost:8080 +# Leave empty to use proxy (recommended for local dev and production) +# Or set full URL like http://localhost:8081 for direct API access +VITE_API_URL= diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 52c5cda..c267175 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -16,6 +16,19 @@ server { add_header Cache-Control "public, immutable"; } + # Proxy API requests to backend + location /api/ { + proxy_pass http://backend:8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + 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_cache_bypass $http_upgrade; + } + # Handle client-side routing location / { try_files $uri $uri/ /index.html; diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 06f6242..f4cc6b3 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -1,4 +1,4 @@ -const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:8080'; +const API_BASE_URL = import.meta.env.VITE_API_URL || ''; // Request deduplication cache const pendingRequests = new Map>(); diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 72201e0..3ddb5b8 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -27,5 +27,11 @@ export default defineConfig({ ], server: { allowedHosts: ['delivery.loca.lt', '.loca.lt'], + proxy: { + '/api': { + target: 'http://localhost:8081', + changeOrigin: true, + }, + }, }, }) \ No newline at end of file