| <?php |
| |
|
|
| $request_uri = $_SERVER['REQUEST_URI']; |
|
|
| |
| $path_without_editor = preg_replace('#^/editor/#', '/', $request_uri); |
|
|
| |
| $base_url = 'https://s4s-editor.vercel.app'; |
|
|
| |
| $target_url = $base_url . $path_without_editor; |
|
|
| |
| $ch = curl_init($target_url); |
|
|
| |
| curl_setopt_array($ch, [ |
| CURLOPT_RETURNTRANSFER => true, |
| CURLOPT_HEADER => true, |
| CURLOPT_FOLLOWLOCATION => true, |
| CURLOPT_SSL_VERIFYPEER => false, |
| CURLOPT_ENCODING => "", // gzip/deflate 対応 |
| CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0, // HTTP/2強制(可能なら) |
| ]); |
|
|
| $response = curl_exec($ch); |
|
|
| if (curl_errno($ch)) { |
| http_response_code(502); |
| echo "取得エラー: " . curl_error($ch); |
| curl_close($ch); |
| exit; |
| } |
|
|
| |
| $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
| $header_text = substr($response, 0, $header_size); |
| $body = substr($response, $header_size); |
|
|
| |
| if (preg_match('/^Content-Type:\s*(.+)$/im', $header_text, $matches)) { |
| header('Content-Type: ' . trim($matches[1])); |
| } |
|
|
| |
| echo $body; |
| curl_close($ch); |
| ?> |
|
|