You can now easily switch between development and production API URLs by changing just one setting!
File: frontend/src/lib/apiConfig.ts
// β‘ QUICK SWITCH: Change this to easily switch between environments
// Set to 'local' for development, 'production' for live deployment
ENVIRONMENT: 'local' as 'local' | 'production',- Local Development:
http://localhost:5001/api - Production:
https://vgurad-backend.onrender.com/api
- For Development: Change
ENVIRONMENT: 'local' - For Production: Change
ENVIRONMENT: 'production'
That's it! All components will automatically use the correct URL.
The following files have been updated to use the centralized configuration:
β IoT Components:
frontend/src/components/iot/AdvancedAlerts.tsxfrontend/src/components/iot/IoTDeviceManager.tsxfrontend/src/components/iot/ConnectDeviceGuide.tsxfrontend/src/pages/IoTDashboard.tsx
β Profile & Auth:
frontend/src/components/ProfilePage.tsx
β Expert Help:
frontend/src/components/ExpertHelp.tsx(partial)
These files still have hardcoded URLs and need manual updating:
frontend/src/components/DiseaseDatabase.tsxfrontend/src/pages/MarketPrices.tsxfrontend/src/components/TreatmentCalendar.tsxfrontend/src/components/ProtectedRoute.tsxfrontend/src/components/Marketplace.tsxfrontend/src/components/Header.tsxfrontend/src/components/FarmerTips.tsx
- Add import:
import { API_BASE_URL } from '@/lib/apiConfig'; - Replace hardcoded URLs:
- From:
'https://vgurad-backend.onrender.com/api/endpoint' - To:
\${API_BASE_URL}/endpoint``
- From:
- β One-click switching between environments
- β No more manual find & replace
- β Centralized configuration
- β Environment-specific builds
- β Easy deployment process
You can also use environment variables in .env.local and .env.production:
# .env.local
VITE_API_BASE_URL=http://localhost:5001/api
# .env.production
VITE_API_BASE_URL=https://vgurad-backend.onrender.com/apiThe system will respect this priority:
- Manual
ENVIRONMENTsetting inapiConfig.ts - Environment variables (VITE_API_BASE_URL)
- Default fallback URL