add files
This commit is contained in:
40
proxy/proxy.php
Normal file
40
proxy/proxy.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$proxyUrl = 'http://127.0.0.1:3000/proxy'; // Das Proxy-Endpunkt auf dem Express-Server
|
||||
|
||||
// Überprüfe, ob die URL als GET- oder POST-Parameter übergeben wurde
|
||||
$externalUrl = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
if (isset($_GET['url'])) {
|
||||
$externalUrl = $_GET['url'];
|
||||
}
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
if (isset($data['url'])) {
|
||||
$externalUrl = $data['url'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($externalUrl)) {
|
||||
// Daten als JSON-String vorbereiten
|
||||
$data = json_encode(array('url' => $externalUrl));
|
||||
|
||||
$ch = curl_init($proxyUrl);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // Den Content-Type auf JSON setzen
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// Antwort des Proxys an den Client ausgeben
|
||||
// Setze den Content-Type-Header entsprechend, um die Antwort als HTML, Text, CSS und JavaScript zu behandeln
|
||||
// header('Content-Type: text/html'); // Oder 'text/plain', 'text/css', 'application/javascript', je nachdem, was du erwartest
|
||||
|
||||
echo $response;
|
||||
} else {
|
||||
// Wenn die URL nicht übergeben wurde, gebe einen Fehler zurück
|
||||
echo json_encode(array('error' => 'URL fehlt'));
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user