diff --git a/engine/classes/DealProxy.php b/engine/classes/DealProxy.php index a763a17..75cc887 100644 --- a/engine/classes/DealProxy.php +++ b/engine/classes/DealProxy.php @@ -1,10 +1,7 @@ logFile, "[$date] $message\n", FILE_APPEND); } /** Build the target URL based on incoming request */ - private function buildTargetUrl(): string + private function buildTargetUrl() { - $path = $_GET['path'] ?? ''; + $path = isset($_GET['path']) ? $_GET['path'] : ''; unset($_GET['path']); $query = http_build_query($_GET); $apiUrl = "https://llar.joyworkdev.ru/api/" . ltrim($path, '/'); @@ -37,14 +34,14 @@ class DealProxy } /** Build headers for the forwarded request */ - private function buildHeaders(): array + private function buildHeaders() { - $headers = [ + $headers = array( 'Accept: application/json', - ]; + ); // Preserve original Content-Type if present - $originalContentType = $_SERVER['CONTENT_TYPE'] ?? ''; + $originalContentType = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''; if ($originalContentType) { $headers[] = 'Content-Type: ' . $originalContentType; $this->logMessage("Incoming Content-Type: '$originalContentType'"); @@ -64,17 +61,17 @@ class DealProxy } /** Forward the request using cURL and output the response */ - private function forwardRequest(string $targetUrl, array $headers, string $method, string $body): void + private function forwardRequest($targetUrl, $headers, $method, $body) { $ch = curl_init(); - curl_setopt_array($ch, [ + curl_setopt_array($ch, array( CURLOPT_URL => $targetUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => $headers, CURLOPT_HEADER => false, - ]); + )); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); @@ -89,9 +86,9 @@ class DealProxy } /** Main handler – called from index.php */ - public function handle(): void + public function handle() { - // CORS headers – keep them here to be sent before any output + // CORS headers – must be sent before any output header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');