#!/bin/bash # This script updates the backend URL and rebuilds the application # Define the backend URL BACKEND_URL="https://ai-sandbox.oliver.solutions/netflix_back_v2" # Create or update the environment files echo "# Backend API URL VITE_BACKEND_URL=${BACKEND_URL} # Base URL for the app (changes in production) VITE_APP_BASE_URL=/" > .env echo "# Production backend API URL VITE_BACKEND_URL=${BACKEND_URL} # Base URL for the app in production VITE_APP_BASE_URL=/netflix_v2/" > .env.production # Update components files for file in src/components/ChatInterface.jsx src/components/ConversationManager.jsx src/App.jsx; do # Replace hardcoded backend URL references sed -i '' "s|const BACKEND_URL = ['\"]\/netflix_back_v2['\"]|const BACKEND_URL = import.meta.env.VITE_BACKEND_URL || '${BACKEND_URL}'|g" $file sed -i '' "s|console.log('.*using backend URL (hardcoded):|console.log('Using backend URL:|g" $file done # Update vite.config.js to use the replacement plugin sed -i '' 's|plugins: \[react()\],|plugins: [react(), replaceBackendUrl],|g' vite.config.js sed -i '' 's|code: src.replace(/\['"'\]\/netflix_back\['"'\]/g, '"\/netflix_back_v2"'),|code: src.replace(/\['"'\]\/netflix_back\['"'\]/g, `"${BACKEND_URL}"`),|g' vite.config.js # Force a complete rebuild by removing all assets rm -rf dist/assets/* # Rebuild the application npm run build echo "Update complete! The backend URL has been set to ${BACKEND_URL}"