#!/bin/bash # Environment Setup Script for Royal Enfield Workflow Frontend echo "==================================================" echo "Royal Enfield - Frontend Environment Setup" echo "==================================================" echo "" # Function to create .env.example create_env_example() { cat > .env.example << 'EOF' # API Configuration # Backend API base URL (with /api/v1) VITE_API_BASE_URL=http://localhost:5000/api/v1 # Base URL for direct file access (without /api/v1) VITE_BASE_URL=http://localhost:5000 EOF echo "✅ Created .env.example" } # Function to create .env.local create_env_local() { cat > .env.local << 'EOF' # Local Development Environment VITE_API_BASE_URL=http://localhost:5000/api/v1 VITE_BASE_URL=http://localhost:5000 EOF echo "✅ Created .env.local (for local development)" } # Function to create .env.production template create_env_production() { echo "" echo "==================================================" echo "Production Environment Configuration" echo "==================================================" echo "" read -p "Enter your PRODUCTION backend URL (e.g., https://api.yourcompany.com): " BACKEND_URL if [ -z "$BACKEND_URL" ]; then echo "⚠️ No backend URL provided. Creating template file..." cat > .env.production << 'EOF' # Production Environment # IMPORTANT: Update these URLs with your actual deployed backend URL VITE_API_BASE_URL=https://your-backend-url.com/api/v1 VITE_BASE_URL=https://your-backend-url.com EOF else # Remove trailing slash if present BACKEND_URL=${BACKEND_URL%/} cat > .env.production << EOF # Production Environment VITE_API_BASE_URL=${BACKEND_URL}/api/v1 VITE_BASE_URL=${BACKEND_URL} EOF echo "✅ Created .env.production with backend URL: ${BACKEND_URL}" fi } # Main execution echo "This script will create environment configuration files for your frontend." echo "" # Check if files already exist if [ -f ".env.local" ] || [ -f ".env.production" ]; then echo "⚠️ Environment files already exist:" [ -f ".env.local" ] && echo " - .env.local" [ -f ".env.production" ] && echo " - .env.production" echo "" read -p "Do you want to OVERWRITE them? (y/n): " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Aborted. No files were modified." exit 0 fi fi # Create files create_env_example create_env_local create_env_production echo "" echo "==================================================" echo "✅ Setup Complete!" echo "==================================================" echo "" echo "Next Steps:" echo "" echo "1. For LOCAL development:" echo " npm run dev" echo " (will use .env.local automatically)" echo "" echo "2. For PRODUCTION deployment:" echo " - If deploying to Vercel/Netlify/etc:" echo " Set environment variables in your platform dashboard" echo " - If using Docker/VM:" echo " Ensure .env.production has correct URLs" echo "" echo "3. Update Okta Configuration:" echo " - Add production callback URL to Okta app settings" echo " - Sign-in redirect URI: https://your-frontend.com/login/callback" echo "" echo "4. Update Backend CORS:" echo " - Add production frontend URL to CORS allowed origins" echo "" echo "📖 For detailed instructions, see: DEPLOYMENT_CONFIGURATION.md" echo ""