Add files via upload

Aded proxy file to get rid of CORS problems
This commit is contained in:
erikklavora 2025-10-05 14:17:41 +02:00 committed by GitHub
parent 50c4e4d022
commit b578dbafd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

62
proxy.php Normal file
View file

@ -0,0 +1,62 @@
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
// Handle preflight OPTIONS request
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
$apiUrl = 'https://map.meshcore.dev/api/v1/nodes';
// Initialize cURL
$ch = curl_init();
// Set the URL
curl_setopt($ch, CURLOPT_URL, $apiUrl);
// Set request method
$method = $_SERVER['REQUEST_METHOD'];
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
// Set headers
$headers = [
'Content-Type: application/json',
'User-Agent: MeshCore Map Proxy'
];
// Forward request body for POST requests
if ($method === 'POST') {
$input = file_get_contents('php://input');
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
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);
// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Check for cURL errors
if (curl_error($ch)) {
http_response_code(500);
echo json_encode(['error' => 'Proxy error: ' . curl_error($ch)]);
curl_close($ch);
exit();
}
curl_close($ch);
// Set the HTTP response code
http_response_code($httpCode);
// Return the response
echo $response;
?>