diff --git a/.gitignore b/.gitignore index a3fe099..28ee60e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ dist-ssr # Environment variables .env +# CORS-Proxy Konfiguration (enthält Credentials) +cors-config.php + # Editor directories and files .vscode/* !.vscode/extensions.json diff --git a/ACHTUNG.md b/ACHTUNG.md new file mode 100644 index 0000000..2e22497 --- /dev/null +++ b/ACHTUNG.md @@ -0,0 +1,13 @@ +# ACHTUNG +2025-10-29 + +Es gibt extreme Probleme mit CORS beim Zugriff auf die Sternwarte. Lokal auf localhost funtioniert die Anwendung jetzt richtig gut. + +M.E. macht es keinen Sinn, so weiter zu machen. Sinnvoll ist es, einen neuen Server für die Sternwarte aufzusetzen, auf dem man dann problemlos das Alles laufen lassen kann (da ja dann Alles 'localhost' ist.) + +Vorschlag: IONOS oder STRATO oder HETZNER oder .... + +Vergleich in einer Numbers-Tabelle (in der iCloud unter Numbers/Vergleich_Server) + + +rxf \ No newline at end of file diff --git a/cors-proxy.php b/cors-proxy.php new file mode 100644 index 0000000..70f2227 --- /dev/null +++ b/cors-proxy.php @@ -0,0 +1,114 @@ + + } +} + +// Option 3: Letzter Fallback - aber sicherer als Klartext +if (!$username || !$password) { + // Base64-kodiert (minimal obfuskiert, aber nicht wirklich sicher) + $encoded = 'YmVvZ3J1cHBlOkFya3RVaHI='; // beogruppe:ArktUhr + $decoded = base64_decode($encoded); + list($username, $password) = explode(':', $decoded, 2); +} + +// Sicherheitscheck +if (!$username || !$password) { + http_response_code(500); + echo 'Server configuration error'; + exit(); +} + +// POST-Daten aus dem Frontend übernehmen +$postData = $_POST; + +// Debug-Log (optional, für Entwicklung) +error_log("CORS-Proxy: Weiterleitung an Backend mit " . count($postData) . " Parametern"); + +// cURL-Request an das geschützte Backend +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, $backendUrl); +curl_setopt($ch, CURLOPT_POST, true); +curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); +curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); +curl_setopt($ch, CURLOPT_TIMEOUT, 30); + +// Response vom Backend holen +$response = curl_exec($ch); +$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); +$error = curl_error($ch); +curl_close($ch); + +// Fehlerbehandlung +if ($response === false) { + http_response_code(500); + echo "Backend-Verbindungsfehler: " . $error; + exit(); +} + +// HTTP-Status vom Backend übernehmen +http_response_code($httpCode); + +// Content-Type vom Backend übernehmen (falls JSON) +if (strpos($response, '{') === 0 || strpos($response, '[') === 0) { + header('Content-Type: application/json'); +} else { + header('Content-Type: text/plain'); +} + +// Response vom Backend weiterleiten +echo $response; +?> \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index 0f409c8..ff57000 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -51,7 +51,7 @@ function AppContent() { console.log('Loading data for ID:', id) - // Backend-Aufruf mit Proxy + // Backend-Aufruf mit HTTP Basic Auth const formData = new FormData() formData.append('cmd', 'GET_ONE') formData.append('id', id) diff --git a/src/components/LastButtons.jsx b/src/components/LastButtons.jsx index 3fe8fc1..9d4d564 100644 --- a/src/components/LastButtons.jsx +++ b/src/components/LastButtons.jsx @@ -20,11 +20,11 @@ export default function LastButtons({ mitSend, mitBack, handleBack}) { setIsSending(true) try { - // API URL und Auth-Daten aus Environment + // API URL aus Environment Variable const APIURL = import.meta.env.VITE_API_URL const username = import.meta.env.VITE_API_USERNAME const password = import.meta.env.VITE_API_PASSWORD - + if (!APIURL) { throw new Error('API URL nicht konfiguriert.') }