# ═══════════════════════════════════════════════════════════════════════════ # EmailSorter - Appwrite CORS Platform Setup (Automatisch) # ═══════════════════════════════════════════════════════════════════════════ # Dieses Script fügt automatisch die Production-Platform zu Appwrite hinzu, # um CORS-Fehler zu beheben. # # Voraussetzungen: # - Appwrite läuft unter https://appwrite.webklar.com # - Du bist bereits eingeloggt in Appwrite (Browser-Session) # - PowerShell ExecutionPolicy erlaubt Scripts (Set-ExecutionPolicy RemoteSigned) # ═══════════════════════════════════════════════════════════════════════════ param( [string]$AppwriteUrl = "https://appwrite.webklar.com", [string]$ProjectId = "", [string]$PlatformHostname = "emailsorter.webklar.com", [string]$PlatformOrigin = "https://emailsorter.webklar.com" ) # Lade .env Datei falls vorhanden $envFile = "..\server\.env" if (Test-Path $envFile) { Get-Content $envFile | ForEach-Object { if ($_ -match '^\s*([^#][^=]*)=(.*)$') { $key = $matches[1].Trim() $value = $matches[2].Trim() [Environment]::SetEnvironmentVariable($key, $value, "Process") } } } # Verwende Project ID aus .env falls nicht als Parameter übergeben if ([string]::IsNullOrEmpty($ProjectId)) { $ProjectId = $env:APPWRITE_PROJECT_ID } if ([string]::IsNullOrEmpty($ProjectId)) { Write-Host "❌ Keine Project ID gefunden!" -ForegroundColor Red Write-Host " Bitte gib die Project ID als Parameter an oder setze APPWRITE_PROJECT_ID in server/.env" -ForegroundColor Yellow exit 1 } Write-Host "`n🔧 Appwrite CORS Platform Setup" -ForegroundColor Cyan Write-Host "═══════════════════════════════════════════════════════════════" -ForegroundColor Cyan Write-Host "" Write-Host "Appwrite URL: $AppwriteUrl" -ForegroundColor Gray Write-Host "Project ID: $ProjectId" -ForegroundColor Gray Write-Host "Platform Host: $PlatformHostname" -ForegroundColor Gray Write-Host "Platform Origin: $PlatformOrigin" -ForegroundColor Gray Write-Host "" # Prüfe ob Selenium WebDriver verfügbar ist $seleniumAvailable = $false try { $seleniumModule = Get-Module -ListAvailable -Name "Selenium" -ErrorAction SilentlyContinue if ($null -eq $seleniumModule) { Write-Host "📦 Installiere Selenium WebDriver..." -ForegroundColor Yellow Install-Module -Name "Selenium" -Scope CurrentUser -Force -ErrorAction SilentlyContinue | Out-Null } Import-Module Selenium -ErrorAction SilentlyContinue $seleniumAvailable = $true } catch { Write-Host "⚠️ Selenium WebDriver nicht verfügbar. Verwende manuelle Methode." -ForegroundColor Yellow $seleniumAvailable = $false } if (-not $seleniumAvailable) { Write-Host "" Write-Host "💡 MANUELLE METHODE:" -ForegroundColor Yellow Write-Host "" Write-Host "Da Browser-Automatisierung nicht verfügbar ist, bitte folge diesen Schritten:" -ForegroundColor White Write-Host "" Write-Host "1. Öffne deinen Browser und gehe zu:" -ForegroundColor Cyan Write-Host " $AppwriteUrl" -ForegroundColor White Write-Host "" Write-Host "2. Logge dich ein (falls noch nicht geschehen)" -ForegroundColor Cyan Write-Host "" Write-Host "3. Öffne dein Projekt (Project ID: $ProjectId)" -ForegroundColor Cyan Write-Host "" Write-Host "4. Gehe zu Settings → Platforms (oder 'Web' in manchen Versionen)" -ForegroundColor Cyan Write-Host "" Write-Host "5. Klicke auf 'Add Platform' oder 'Create Platform'" -ForegroundColor Cyan Write-Host "" Write-Host "6. Wähle 'Web' als Platform-Typ" -ForegroundColor Cyan Write-Host "" Write-Host "7. Fülle die Felder aus:" -ForegroundColor Cyan Write-Host " - Name: Production" -ForegroundColor White Write-Host " - Hostname: $PlatformHostname" -ForegroundColor White Write-Host " - Origin: $PlatformOrigin (falls gefragt)" -ForegroundColor White Write-Host "" Write-Host "8. Speichere und warte 1-2 Minuten" -ForegroundColor Cyan Write-Host "" Write-Host "✅ Danach sollten die CORS-Fehler verschwinden!" -ForegroundColor Green Write-Host "" exit 0 } # Browser-Automatisierung mit Selenium Write-Host "🌐 Starte Browser-Automatisierung..." -ForegroundColor Yellow try { # Starte Chrome Browser $driver = Start-SeChrome -Headless:$false Write-Host "✓ Browser gestartet" -ForegroundColor Green # Navigiere zu Appwrite Write-Host "📡 Navigiere zu Appwrite..." -ForegroundColor Yellow $driver.Navigate().GoToUrl("$AppwriteUrl/console/project-$ProjectId/settings/platforms") Start-Sleep -Seconds 3 Write-Host "" Write-Host "⚠️ WICHTIG: Bitte führe die folgenden Schritte manuell im Browser aus:" -ForegroundColor Yellow Write-Host "" Write-Host "1. Falls du nicht eingeloggt bist, logge dich jetzt ein" -ForegroundColor Cyan Write-Host "2. Die Platform-Seite sollte bereits geöffnet sein" -ForegroundColor Cyan Write-Host "3. Klicke auf 'Add Platform' oder 'Create Platform'" -ForegroundColor Cyan Write-Host "4. Wähle 'Web' als Platform-Typ" -ForegroundColor Cyan Write-Host "5. Fülle aus:" -ForegroundColor Cyan Write-Host " - Name: Production" -ForegroundColor White Write-Host " - Hostname: $PlatformHostname" -ForegroundColor White Write-Host " - Origin: $PlatformOrigin" -ForegroundColor White Write-Host "6. Klicke auf 'Create' oder 'Save'" -ForegroundColor Cyan Write-Host "" Write-Host "Drücke Enter, wenn du fertig bist..." -ForegroundColor Yellow Read-Host Write-Host "" Write-Host "✅ Platform sollte jetzt hinzugefügt sein!" -ForegroundColor Green Write-Host "" Write-Host "📝 Warte 1-2 Minuten, damit die CORS-Änderungen wirksam werden." -ForegroundColor Yellow Write-Host " Danach sollten die CORS-Fehler verschwinden." -ForegroundColor Yellow Write-Host "" # Browser bleibt offen für manuelle Schritte Write-Host "Browser bleibt geöffnet. Schließe ihn manuell, wenn du fertig bist." -ForegroundColor Gray } catch { Write-Host "" Write-Host "❌ Fehler bei Browser-Automatisierung: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" Write-Host "💡 Bitte verwende die manuelle Methode (siehe oben)" -ForegroundColor Yellow exit 1 }