Projektarbeit-MYP/frontend/check-backend-connection.sh
Till Tomczak 62e131c02f """
feat: Update frontend and backend configurations for development environment

- Downgrade PyP100 version in requirements.txt for compatibility.
- Add new frontend routes for index, login, dashboard, printers, jobs, and profile pages.
- Modify docker-compose files for development setup, including environment variables and service names.
- Update Caddyfile for local development with Raspberry Pi backend.
- Adjust health check route to use updated backend URL.
- Enhance setup-backend-url.sh for development environment configuration.
"""
2025-05-24 18:58:17 +02:00

157 lines
5.9 KiB
Bash
Executable File

#!/bin/bash
# 🔍 MYP Frontend - Backend-Verbindung prüfen
# Entwicklungsumgebung - Überprüft Verbindung zum Raspberry Pi Backend auf 192.168.0.105:5000
set -e
# Farben für Terminal-Ausgabe
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Funktionen
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Arbeitsverzeichnis setzen
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "🔍 MYP Frontend - Backend-Verbindung wird überprüft..."
echo "🍓 Entwicklungsumgebung - Raspberry Pi Backend"
echo "=================================================="
# Backend-URL definieren (Hardcoded für Raspberry Pi)
BACKEND_URL="http://192.168.0.105:5000"
BACKEND_API_URL="$BACKEND_URL/api"
RASPBERRY_PI_HOST="192.168.0.105"
log_info "Ziel-Backend: $BACKEND_URL (Raspberry Pi)"
echo ""
# 1. Netzwerk-Konnektivität zum Raspberry Pi prüfen
log_info "1. Prüfe Netzwerk-Konnektivität zum Raspberry Pi ($RASPBERRY_PI_HOST)..."
if ping -c 1 -W 3 $RASPBERRY_PI_HOST >/dev/null 2>&1; then
log_success "✓ Ping zum Raspberry Pi erfolgreich"
else
log_error "✗ Ping zum Raspberry Pi fehlgeschlagen"
log_error " Stellen Sie sicher, dass der Raspberry Pi erreichbar ist"
log_error " Prüfen Sie die Netzwerkverbindung und IP-Adresse"
fi
# 2. Backend-Service auf Raspberry Pi prüfen
log_info "2. Prüfe Backend-Service auf Raspberry Pi Port 5000..."
if curl -f --connect-timeout 5 "$BACKEND_URL/health" >/dev/null 2>&1; then
log_success "✓ Raspberry Pi Backend-Health-Check erfolgreich"
elif curl -f --connect-timeout 5 "$BACKEND_URL" >/dev/null 2>&1; then
log_warning "⚠ Raspberry Pi Backend erreichbar, aber kein Health-Endpoint"
else
log_error "✗ Raspberry Pi Backend-Service nicht erreichbar"
log_error " Stellen Sie sicher, dass das Backend auf dem Raspberry Pi läuft"
log_error " Prüfen Sie: ssh pi@$RASPBERRY_PI_HOST 'sudo systemctl status myp-backend'"
fi
# 3. API-Endpunkte auf Raspberry Pi prüfen
log_info "3. Prüfe Raspberry Pi Backend-API-Endpunkte..."
for endpoint in "printers" "jobs" "users"; do
if curl -f --connect-timeout 5 "$BACKEND_API_URL/$endpoint" >/dev/null 2>&1; then
log_success "✓ API-Endpunkt /$endpoint auf Raspberry Pi erreichbar"
else
log_warning "⚠ API-Endpunkt /$endpoint auf Raspberry Pi nicht erreichbar"
fi
done
echo ""
# 4. Frontend-Konfigurationsdateien für Entwicklung prüfen
log_info "4. Prüfe Frontend-Konfigurationsdateien (Entwicklungsumgebung)..."
# .env.local prüfen
if [ -f ".env.local" ]; then
if grep -q "NEXT_PUBLIC_API_URL=http://192.168.0.105:5000" .env.local; then
log_success "✓ .env.local korrekt für Raspberry Pi konfiguriert"
else
log_warning "⚠ .env.local existiert, aber Raspberry Pi Backend-URL ist falsch"
log_info " Führen Sie './setup-backend-url.sh' aus"
fi
else
log_warning "⚠ .env.local nicht gefunden"
log_info " Führen Sie './setup-backend-url.sh' aus"
fi
# env.frontend prüfen
if grep -q "NODE_ENV=development" env.frontend && grep -q "NEXT_PUBLIC_API_URL=http://192.168.0.105:5000" env.frontend; then
log_success "✓ env.frontend korrekt für Entwicklungsumgebung konfiguriert"
else
log_error "✗ env.frontend nicht für Entwicklungsumgebung konfiguriert"
fi
# api-config.ts prüfen
if grep -q 'API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://192.168.0.105:5000"' src/utils/api-config.ts; then
log_success "✓ api-config.ts korrekt für Raspberry Pi konfiguriert"
else
log_error "✗ api-config.ts hat falsche Standard-URL"
fi
# Docker-Compose-Dateien für Entwicklung prüfen
if grep -q "NODE_ENV=development" docker-compose.yml && grep -q "NEXT_PUBLIC_API_URL=http://192.168.0.105:5000" docker-compose.yml; then
log_success "✓ docker-compose.yml korrekt für Entwicklungsumgebung konfiguriert"
else
log_warning "⚠ docker-compose.yml nicht für Entwicklungsumgebung konfiguriert"
fi
# Caddy-Konfiguration für Entwicklung prüfen
if grep -q "reverse_proxy 192.168.0.105:5000" docker/caddy/Caddyfile && grep -q "localhost" docker/caddy/Caddyfile; then
log_success "✓ Caddy-Konfiguration korrekt für Entwicklungsumgebung"
else
log_error "✗ Caddy-Konfiguration nicht für Entwicklungsumgebung konfiguriert"
fi
echo ""
# 5. Zusammenfassung und Empfehlungen für Entwicklungsumgebung
log_info "5. Zusammenfassung und Empfehlungen (Entwicklungsumgebung):"
echo ""
if ping -c 1 -W 3 $RASPBERRY_PI_HOST >/dev/null 2>&1 && curl -f --connect-timeout 5 "$BACKEND_URL" >/dev/null 2>&1; then
log_success "🎉 Raspberry Pi Backend ist erreichbar und läuft!"
echo ""
log_info "Nächste Schritte (Entwicklung):"
echo " 1. Frontend starten: ./start-frontend-server.sh"
echo " 2. Frontend testen: http://localhost:3000"
echo " 3. Health-Check: http://localhost:3000/health"
echo " 4. Backend-Health: http://localhost:3000/backend-health"
else
log_error "❌ Raspberry Pi Backend ist nicht erreichbar!"
echo ""
log_info "Fehlerbehebung (Entwicklungsumgebung):"
echo " 1. Prüfen Sie, ob der Raspberry Pi ($RASPBERRY_PI_HOST) läuft"
echo " 2. SSH zum Raspberry Pi: ssh pi@$RASPBERRY_PI_HOST"
echo " 3. Backend-Status prüfen: sudo systemctl status myp-backend"
echo " 4. Backend-Logs prüfen: sudo journalctl -u myp-backend -f"
echo " 5. Netzwerk-Konnektivität prüfen"
echo " 6. Firewall-Einstellungen auf Raspberry Pi prüfen"
fi
echo ""
log_info "Debug-Tools:"
echo " - Debug-Server: ./debug-server/start-debug-server.sh"
echo " - Backend direkt: curl http://192.168.0.105:5000/health"
echo " - SSH zum Raspberry Pi: ssh pi@192.168.0.105"
echo "=================================================="