'API backend is unavailable', 'details' => $curlError, ]); exit; } http_response_code($httpCode > 0 ? $httpCode : 200); header('Content-Type: application/json'); echo $response; exit; } // Serve existing static files so asset requests are not rewritten to HTML. $documentRoot = realpath(__DIR__); $resolvedFile = realpath(__DIR__ . $requestPath); if ( $documentRoot !== false && $resolvedFile !== false && strpos($resolvedFile, $documentRoot) === 0 && is_file($resolvedFile) && strtolower(pathinfo($resolvedFile, PATHINFO_EXTENSION)) !== 'php' ) { $contentType = function_exists('mime_content_type') ? mime_content_type($resolvedFile) : false; if ($contentType === false) { $ext = strtolower(pathinfo($resolvedFile, PATHINFO_EXTENSION)); $map = [ 'css' => 'text/css', 'js' => 'application/javascript', 'mjs' => 'application/javascript', 'json' => 'application/json', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'ico' => 'image/x-icon', 'woff' => 'font/woff', 'woff2' => 'font/woff2', 'ttf' => 'font/ttf', 'html' => 'text/html', ]; $contentType = $map[$ext] ?? 'application/octet-stream'; } header('Content-Type: ' . $contentType); readfile($resolvedFile); exit; } // SPA fallback header('Content-Type: text/html'); readfile(__DIR__ . '/erp-index.html');