From 1ad57d16c32cbf9c7b20150555fc1b45edf05dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B8=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B8=CC=86=20=D0=91=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 7 Nov 2025 02:31:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/requirements.txt | 1 + backend/settings/settings.py | 17 ++++++++++++++++- compose.yaml | 5 +++-- frontend/src/network.ts | 10 +++++++--- frontend/vite.config.ts | 25 +------------------------ 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index af9acca..4c0cffe 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,4 +1,5 @@ Django==5.2.7 +django-cors-headers aiohttp requests pytz diff --git a/backend/settings/settings.py b/backend/settings/settings.py index 129a2b0..c807b5c 100644 --- a/backend/settings/settings.py +++ b/backend/settings/settings.py @@ -26,12 +26,26 @@ SECRET_KEY = 'django-insecure-=cldztbc4jg&xl0!x673!*v2_=p$$eu)=7*f#d0#zs$44xx-h^ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['localhost', '127.0.0.1', '192.168.1.100', 'shop.softwarrior.ru'] +ALLOWED_HOSTS = ['localhost', '127.0.0.1', '192.168.1.100', 'shop-api.softwarrior.ru', 'shop.softwarrior.ru'] +CORS_ALLOWED_ORIGINS = [ + "https://shop.softwarrior.ru", + "https://shop-api.softwarrior.ru", + "http://localhost:5173", + "http://127.0.0.1:5173", +] + +CSRF_TRUSTED_ORIGINS = [ + "https://shop.softwarrior.ru", + "https://shop-api.softwarrior.ru", + "http://localhost:5173", + "http://127.0.0.1:5173", +] # Application definition INSTALLED_APPS = [ + 'corsheaders', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -42,6 +56,7 @@ INSTALLED_APPS = [ ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', diff --git a/compose.yaml b/compose.yaml index c1a894a..4cc3d08 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,12 +3,13 @@ version: '3.8' services: frontend: platform: linux/arm64/v8 + image: firstsoftwarrior/shop-frontend build: context: frontend target: development container_name: firstsoftwarrior-shop-frontend ports: - - "8090:8090" + - '8090:8090' environment: - NODE_ENV=development volumes: @@ -19,6 +20,7 @@ services: backend: platform: linux/arm64/v8 + image: firstsoftwarrior/shop-backend build: context: backend target: builder @@ -27,7 +29,6 @@ services: - '8091:8091' environment: - DEBUG=True - - ALLOWED_HOSTS=localhost,127.0.0.1,192.168.1.100,backend,shop.softwarrior.ru volumes: - ./backend:/backend diff --git a/frontend/src/network.ts b/frontend/src/network.ts index b28300e..dfa538f 100644 --- a/frontend/src/network.ts +++ b/frontend/src/network.ts @@ -1,7 +1,11 @@ import { token } from './utils' -const DEV_URL = '/dev_api' -const PROD_URL = 'https://shop.softwarrior.ru:8091' +const DEV_URL = 'http://localhost:8091' +const PROD_URL = 'https://shop-api.softwarrior.ru' + +const isDEV_HOST = + (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') && + window.location.port === '5173' export type ResponseData = { error?: string @@ -25,7 +29,7 @@ class Network implements NetworkApi { private _headers: HeaderType constructor() { - if (import.meta.env.DEV) { + if (import.meta.env.DEV && isDEV_HOST) { this._baseUrl = DEV_URL } else { this._baseUrl = PROD_URL diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 05fa40b..b475318 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -5,29 +5,6 @@ import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], server: { - port: 5173, - proxy: { - '/dev_api': { - target: 'http://localhost:8091', - changeOrigin: true, - secure: false, - rewrite: path => path.replace(/^\/dev_api/, ''), - configure: (proxy, _options) => { - proxy.on('error', (err, _req, _res) => { - console.log('Proxy error:', err) - }) - proxy.on('proxyReq', (proxyReq, req, _res) => { - console.log( - proxyReq, - 'Proxying:', - req.method, - req.url, - '→', - 'http://localhost:8091' + req?.url?.replace('/dev_api', '') - ) - }) - }, - }, - }, + allowedHosts: ['shop.softwarrior.ru'], }, })