Skip to content

Latest commit

Β 

History

History
87 lines (60 loc) Β· 2.52 KB

API_CONFIGURATION_GUIDE.md

File metadata and controls

87 lines (60 loc) Β· 2.52 KB

πŸ”§ API Configuration System

Easy Environment Switching

You can now easily switch between development and production API URLs by changing just one setting!

🎯 Quick Switch Method

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',

🌍 Environment URLs

  • Local Development: http://localhost:5001/api
  • Production: https://vgurad-backend.onrender.com/api

πŸ”„ How to Switch

  1. For Development: Change ENVIRONMENT: 'local'
  2. For Production: Change ENVIRONMENT: 'production'

That's it! All components will automatically use the correct URL.

πŸ“ Updated Files

The following files have been updated to use the centralized configuration:

βœ… IoT Components:

  • frontend/src/components/iot/AdvancedAlerts.tsx
  • frontend/src/components/iot/IoTDeviceManager.tsx
  • frontend/src/components/iot/ConnectDeviceGuide.tsx
  • frontend/src/pages/IoTDashboard.tsx

βœ… Profile & Auth:

  • frontend/src/components/ProfilePage.tsx

βœ… Expert Help:

  • frontend/src/components/ExpertHelp.tsx (partial)

πŸ“‹ Remaining Files to Update

These files still have hardcoded URLs and need manual updating:

  • frontend/src/components/DiseaseDatabase.tsx
  • frontend/src/pages/MarketPrices.tsx
  • frontend/src/components/TreatmentCalendar.tsx
  • frontend/src/components/ProtectedRoute.tsx
  • frontend/src/components/Marketplace.tsx
  • frontend/src/components/Header.tsx
  • frontend/src/components/FarmerTips.tsx

πŸ› οΈ How to Update Remaining Files

  1. Add import: import { API_BASE_URL } from '@/lib/apiConfig';
  2. Replace hardcoded URLs:
    • From: 'https://vgurad-backend.onrender.com/api/endpoint'
    • To: \${API_BASE_URL}/endpoint``

πŸš€ Benefits

  • βœ… One-click switching between environments
  • βœ… No more manual find & replace
  • βœ… Centralized configuration
  • βœ… Environment-specific builds
  • βœ… Easy deployment process

πŸ“ Environment Variables (Alternative)

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/api

The system will respect this priority:

  1. Manual ENVIRONMENT setting in apiConfig.ts
  2. Environment variables (VITE_API_BASE_URL)
  3. Default fallback URL