#!/bin/bash # ============================================================================= # TimeClock v3 - Fix hardcodierte API URLs # ============================================================================= set -e echo "🔧 Ersetze hardcodierte API-URLs durch zentrale Konfiguration..." cd "$(dirname "$0")" # Backup erstellen echo "📦 Erstelle Backup..." tar -czf ~/timeclock-frontend-backup-$(date +%Y%m%d_%H%M%S).tar.gz src/ # .env.production erstellen echo "📝 Erstelle .env.production..." cat > .env.production << 'EOF' # TimeClock v3 - Frontend Production Environment # API Base URL (relativ, da Apache als Proxy dient) VITE_API_URL=/api EOF # .env.development erstellen echo "📝 Erstelle .env.development..." cat > .env.development << 'EOF' # TimeClock v3 - Frontend Development Environment VITE_API_URL=http://localhost:3010/api EOF # Ersetze alle hardcodierten URLs in Views echo "🔄 Ersetze URLs in Views..." # Pattern: http://localhost:3010/api → ${API_URL} # Muss in mehreren Schritten erfolgen, da die Syntax unterschiedlich ist find src/views -name "*.vue" -type f -exec sed -i "s|'http://localhost:3010/api|'\${API_URL}|g" {} \; find src/views -name "*.vue" -type f -exec sed -i 's|"http://localhost:3010/api|"${API_URL}|g' {} \; find src/views -name "*.vue" -type f -exec sed -i 's|`http://localhost:3010/api|`${API_URL}|g' {} \; # Füge API_URL Import hinzu wo benötigt echo "📦 Füge Imports hinzu..." # Einfacher Ansatz: Erstelle eine Liste der Dateien mit API-Aufrufen grep -l "localhost:3010" src/views/*.vue 2>/dev/null | while read -r file; do # Prüfe ob Import bereits vorhanden if ! grep -q "import.*API_BASE_URL.*from.*@/config/api" "$file"; then # Füge Import nach dem ersten