From d3c320169dfe2439a646a20aee9f40a7ad61bb6c Mon Sep 17 00:00:00 2001 From: anibilag Date: Wed, 9 Jul 2025 14:01:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=200.2.2.?= =?UTF-8?q?=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=20backend,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=D0=BE=20=D0=B2=20Docker=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D1=85=D0=BE=D0=B4=D0=B5=20?= =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=20=D1=85=D0=BE=D1=81=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/ZoneCard.tsx | 4 +++- src/components/ZoneForm.tsx | 4 +++- src/services/api.ts | 4 ++-- vite.config.ts | 34 ++++++++++++++++++++-------------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index c381f7a..13dc92c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lawn-mowing-scheduler", "private": true, - "version": "0.2.1", + "version": "0.2.2", "type": "module", "scripts": { "dev": "concurrently \"npm run server\" \"npm run client\"", diff --git a/src/components/ZoneCard.tsx b/src/components/ZoneCard.tsx index 53bbccc..33c39d8 100644 --- a/src/components/ZoneCard.tsx +++ b/src/components/ZoneCard.tsx @@ -10,6 +10,8 @@ interface ZoneCardProps { onDelete: (id: number) => void; } +const API_BASE = import.meta.env.VITE_API_URL; + const ZoneCard: React.FC = ({ zone, onMarkAsMowed, @@ -99,7 +101,7 @@ const ZoneCard: React.FC = ({ {zone.imagePath ? (
{zone.name} diff --git a/src/components/ZoneForm.tsx b/src/components/ZoneForm.tsx index 36a008a..e885741 100644 --- a/src/components/ZoneForm.tsx +++ b/src/components/ZoneForm.tsx @@ -9,6 +9,8 @@ interface ZoneFormProps { onCancel: () => void; } +const API_BASE = import.meta.env.VITE_API_URL; + const ZoneForm: React.FC = ({ zone, onSubmit, onCancel }) => { const [formData, setFormData] = useState({ name: zone?.name || '', @@ -19,7 +21,7 @@ const ZoneForm: React.FC = ({ zone, onSubmit, onCancel }) => { area: zone?.area || 0, }); const [imagePreview, setImagePreview] = useState( - zone?.imagePath ? `http://localhost:3001${zone.imagePath}` : null + zone?.imagePath ? `${API_BASE}${zone.imagePath}` : null ); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); diff --git a/src/services/api.ts b/src/services/api.ts index 1808500..aacf8ee 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -1,6 +1,6 @@ -import { Zone, ZoneFormData, MowingHistory, MowingHistoryResponse, MowingStats, MowingFormData, Mower, MowerFormData, BulkMowingFormData } from '../types/zone'; +import { Zone, ZoneFormData, MowingHistoryResponse, MowingStats, MowingFormData, Mower, MowerFormData, BulkMowingFormData } from '../types/zone'; -const API_BASE = 'http://localhost:3001/api'; +const API_BASE = new URL('api', import.meta.env.VITE_API_URL).toString(); export const api = { async getZones(): Promise { diff --git a/vite.config.ts b/vite.config.ts index c0a35af..3062cee 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,19 +1,25 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - optimizeDeps: { - exclude: ['lucide-react'], - }, - server: { - host: true, // <-- добавлено: позволяет Vite принимать запросы извне (из Nginx) - proxy: { - '/api': { - target: 'http://localhost:3001', - changeOrigin: true, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd()); + + return { + plugins: [react()], + esbuild: { + minifyIdentifiers: false, // Отключаем переименование переменных + }, + optimizeDeps: { + exclude: ['lucide-react'], + }, + server: { + host: true, // <-- добавлено: позволяет Vite принимать запросы извне (из Nginx) + proxy: { + '/api': { + target: env.VITE_API_URL || 'http://localhost:3001', + changeOrigin: true, + }, }, }, - }, + } }); \ No newline at end of file