77 lines
2.7 KiB
Bash
Executable File
77 lines
2.7 KiB
Bash
Executable File
#!/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 <script setup> hinzu
|
|
sed -i '/<script setup>/a import { API_BASE_URL as API_URL } from '\''@/config/api'\''' "$file"
|
|
fi
|
|
done
|
|
|
|
find src/components -name "*.vue" -type f -exec sed -i "s|'http://localhost:3010/api|'\${API_URL}|g" {} \;
|
|
find src/components -name "*.vue" -type f -exec sed -i 's|"http://localhost:3010/api|"${API_URL}|g' {} \;
|
|
find src/components -name "*.vue" -type f -exec sed -i 's|`http://localhost:3010/api|`${API_URL}|g' {} \;
|
|
|
|
grep -l "localhost:3010" src/components/*.vue 2>/dev/null | while read -r file; do
|
|
if ! grep -q "import.*API_BASE_URL.*from.*@/config/api" "$file"; then
|
|
sed -i '/<script setup>/a import { API_BASE_URL as API_URL } from '\''@/config/api'\''' "$file"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "✅ Fertig!"
|
|
echo ""
|
|
echo "📋 Nächste Schritte:"
|
|
echo " 1. npm run build"
|
|
echo " 2. Kopiere dist/ auf den Server"
|
|
echo ""
|
|
echo "🔍 Prüfe ob alle URLs ersetzt wurden:"
|
|
echo " grep -r 'localhost:3010' src/"
|
|
echo ""
|
|
|
|
exit 0
|
|
|