Rückbau auf lokal
ACHTUNG Text
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -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
|
||||
|
||||
13
ACHTUNG.md
Normal file
13
ACHTUNG.md
Normal file
@@ -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
|
||||
114
cors-proxy.php
Normal file
114
cors-proxy.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* CORS Proxy für sofueDB.php
|
||||
* Diese Datei muss in einem öffentlich zugänglichen Verzeichnis der Website liegen
|
||||
*/
|
||||
|
||||
// CORS Headers für Frontend-Zugriff
|
||||
$allowedOrigins = [
|
||||
'http://localhost:5173',
|
||||
'https://ihre-produktions-domain.de' // Ersetzen Sie durch Ihre echte Domain
|
||||
];
|
||||
|
||||
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
|
||||
if (in_array($origin, $allowedOrigins)) {
|
||||
header("Access-Control-Allow-Origin: $origin");
|
||||
} else {
|
||||
// Für Development: localhost mit beliebigen Ports erlauben
|
||||
if (preg_match('/^http:\/\/localhost:\d+$/', $origin)) {
|
||||
header("Access-Control-Allow-Origin: $origin");
|
||||
}
|
||||
}
|
||||
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Authorization");
|
||||
header("Access-Control-Allow-Credentials: true");
|
||||
|
||||
// Preflight-Request abfangen
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
http_response_code(200);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Nur POST-Requests erlauben
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo 'Method Not Allowed';
|
||||
exit();
|
||||
}
|
||||
|
||||
// Backend-URL und Credentials aus Environment oder Config
|
||||
$backendUrl = 'https://sternwarte-welzheim.de/intern/sofue/php/sofueDB.php';
|
||||
|
||||
// Credentials sicher laden - verschiedene Optionen:
|
||||
// Option 1: Aus Environment Variables (empfohlen)
|
||||
$username = getenv('SOFUE_USERNAME') ?: $_ENV['SOFUE_USERNAME'] ?? null;
|
||||
$password = getenv('SOFUE_PASSWORD') ?: $_ENV['SOFUE_PASSWORD'] ?? null;
|
||||
|
||||
// Option 2: Aus separater Config-Datei (Fallback)
|
||||
if (!$username || !$password) {
|
||||
$configFile = __DIR__ . '/cors-config.php';
|
||||
if (file_exists($configFile)) {
|
||||
include $configFile;
|
||||
// cors-config.php sollte enthalten:
|
||||
// <?php $username = 'beogruppe'; $password = 'ArktUhr'; ?>
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
?>
|
||||
@@ -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)
|
||||
|
||||
@@ -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.')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user