diff --git a/engine/classes/DealProxy.php b/engine/classes/DealProxy.php index d509b90..19ec8dc 100644 --- a/engine/classes/DealProxy.php +++ b/engine/classes/DealProxy.php @@ -1,11 +1,9 @@ logFile = __DIR__ . '/proxy.log'; } - /** Simple logger */ private function logMessage($message) { $date = date('Y-m-d H:i:s'); file_put_contents($this->logFile, "[$date] $message\n", FILE_APPEND); } - /** Build the target URL based on incoming request */ +// private function buildTargetUrl() +// { +// $path = isset($_GET['path']) ? $_GET['path'] : ''; +// unset($_GET['path']); +// $query = http_build_query($_GET); +// +// //$apiUrl = "https://api.joywork.ru/" . ltrim($path, '/'); +// +// $baseUrl = 'https://10.91.76.101'; +// +// $apiUrl = rtrim($baseUrl, '/') . '/' . ltrim($path, '/'); +// +// if ($query) { +// $apiUrl .= '?' . $query; +// } +// return $apiUrl; +// } + private function buildTargetUrl() { $path = isset($_GET['path']) ? $_GET['path'] : ''; unset($_GET['path']); - $query = http_build_query($_GET); - $apiUrl = "https://llar.joyworkdev.ru/api/" . ltrim($path, '/'); + + $pathParts = explode('?', $path, 2); + $cleanPath = ltrim($pathParts[0], '/'); + + $queryParams = $_GET; + if (isset($pathParts[1]) && $pathParts[1]) { + parse_str($pathParts[1], $pathQuery); + $queryParams = array_merge($queryParams, $pathQuery); + } + + $query = http_build_query($queryParams); + + $baseUrl = 'https://10.91.76.101'; + $apiUrl = rtrim($baseUrl, '/') . '/' . $cleanPath; + if ($query) { $apiUrl .= '?' . $query; } + return $apiUrl; } - /** Build headers for the forwarded request */ private function buildHeaders() { $headers = array( 'Accept: application/json', + 'Host: api.joywork.ru', ); // Preserve original Content-Type if present @@ -60,7 +88,6 @@ class DealProxy return $headers; } - /** Forward the request using cURL and output the response */ private function forwardRequest($targetUrl, $headers, $method, $body) { $ch = curl_init(); @@ -73,11 +100,23 @@ class DealProxy CURLOPT_HEADER => false, )); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_VERBOSE, true); + $verbose = fopen('php://temp', 'w+'); + curl_setopt($ch, CURLOPT_STDERR, $verbose); + $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); if ($curlError) { + rewind($verbose); + $verboseLog = stream_get_contents($verbose); + $this->logMessage('cURL VERBOSE: ' . $verboseLog); $this->logMessage('cURL Error: ' . $curlError); + } else { + $this->logMessage('cURL Response (first 200 chars): ' . substr($response, 0, 200)); + $this->logMessage('HTTP Code: ' . $httpCode); } curl_close($ch); @@ -85,10 +124,16 @@ class DealProxy echo $response; } - /** Main handler – called from index.php */ public function handle() { - // CORS headers – must be sent before any output + $this->logMessage('=== PROXY REQUEST START ==='); + $this->logMessage('Method: ' . $_SERVER['REQUEST_METHOD']); + $this->logMessage('GET params: ' . print_r($_GET, true)); + $this->logMessage('HTTP_X_SESSION_ID: ' . (isset($_SERVER['HTTP_X_SESSION_ID']) ? $_SERVER['HTTP_X_SESSION_ID'] : 'NOT SET')); + $this->logMessage('HTTP_COOKIE: ' . (isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : 'NOT SET')); + $this->logMessage('Raw input: ' . file_get_contents('php://input')); + + // CORS headers header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');