4.1 KiB
Frontend-API-Konfiguration für separates Backend
Übersicht
Das Frontend wurde konfiguriert, um mit einem Backend auf einem separaten Server unter https://192.168.0.105:443
zu kommunizieren.
Durchgeführte Änderungen
1. API-Basis-URL-Konfiguration (frontend/src/utils/api-config.ts
)
Primäre Backend-URL: https://192.168.0.105:443
Fallback-URLs:
https://192.168.0.105
(ohne expliziten Port)https://raspberrypi
(lokaler Raspberry Pi Fallback)
2. SSL-Zertifikat-Handling
- Selbstsignierte Zertifikate werden automatisch akzeptiert
NODE_TLS_REJECT_UNAUTHORIZED = '0'
für Development
3. API-Endpunkt-Konfiguration
Alle API-Endpunkte wurden angepasst:
export const API_ENDPOINTS = {
PRINTERS: 'https://192.168.0.105:443/api/printers',
JOBS: 'https://192.168.0.105:443/api/jobs',
USERS: 'https://192.168.0.105:443/api/users',
HEALTH: 'https://192.168.0.105:443/health',
AUTH: {
LOGIN: 'https://192.168.0.105:443/api/auth/login',
CALLBACK: 'https://192.168.0.105:443/api/auth/callback',
}
};
4. Fallback-Mechanismus
Das Frontend verfügt über einen robusten Fallback-Mechanismus:
- Primäre Verbindung:
https://192.168.0.105:443
- Fallback 1:
https://192.168.0.105
(Port 443 automatisch) - Fallback 2:
https://raspberrypi
(lokaler Pi)
5. Health Check Integration
Der Health Check wurde angepasst, um die Backend-Konnektivität zu überwachen:
// Health Check prüft Backend unter https://192.168.0.105:443/health
const backendStatus = await fetch(`${backendUrl}/health`);
Environment-Variablen (optional)
Falls gewünscht, kann die Backend-URL über Environment-Variablen überschrieben werden:
# .env.local
NEXT_PUBLIC_API_URL=https://192.168.0.105:443
NODE_TLS_REJECT_UNAUTHORIZED=0
Netzwerk-Konfiguration
Backend-Server-Anforderungen
- HTTPS aktiviert auf Port 443
- CORS konfiguriert für Frontend-Domain
- SSL-Zertifikat (selbstsigniert oder gültig)
- API-Endpunkte verfügbar unter
/api/*
- Health Check verfügbar unter
/health
Firewall-Regeln
# Backend-Server (192.168.0.105)
sudo ufw allow 443/tcp
sudo ufw allow from 192.168.0.0/24 to any port 443
Entwicklung und Testing
Backend-Verbindung testen
# SSL-Verbindung testen
curl -k https://192.168.0.105:443/health
# API-Endpunkte testen
curl -k https://192.168.0.105:443/api/printers
curl -k https://192.168.0.105:443/api/jobs
Frontend-Server starten
cd frontend
pnpm install
pnpm dev
Das Frontend läuft auf http://localhost:3000
und verbindet sich automatisch mit dem Backend unter https://192.168.0.105:443
.
Fehlerbehebung
SSL-Zertifikat-Probleme
Falls SSL-Zertifikat-Fehler auftreten:
- Browser: Besuche
https://192.168.0.105:443
und akzeptiere das Zertifikat manuell - curl: Verwende
-k
Flag für unsichere Verbindungen - fetch:
NODE_TLS_REJECT_UNAUTHORIZED=0
ist bereits gesetzt
Verbindungsprobleme
- Netzwerk: Prüfe ob
192.168.0.105
erreichbar ist - Port: Stelle sicher, dass Port 443 geöffnet ist
- Backend: Prüfe ob Backend-Service läuft
- Logs: Prüfe Browser-Konsole und Backend-Logs
Fallback-Testing
Das Frontend versucht automatisch Fallback-URLs:
// In Browser-Konsole testen
console.log('API_BASE_URL:', API_BASE_URL);
fetch('/api/health').then(r => r.json()).then(console.log);
Produktions-Deployment
Umgebungsspezifische Konfiguration
# Production
NEXT_PUBLIC_API_URL=https://192.168.0.105:443
# Staging
NEXT_PUBLIC_API_URL=https://staging-backend:443
# Development
NEXT_PUBLIC_API_URL=https://localhost:5000
Docker-Deployment
# docker-compose.yml
services:
frontend:
build: ./frontend
environment:
- NEXT_PUBLIC_API_URL=https://192.168.0.105:443
ports:
- "3000:3000"
Status: ✅ Konfiguration abgeschlossen
Backend-URL: https://192.168.0.105:443
Fallback-Support: Aktiviert
SSL-Handling: Selbstsignierte Zertifikate akzeptiert
Getestet: Bereit für Integration