<?php
// proxy.php — put next to your HTML file
$target = 'http://192.168.1.150:5678';
$path = $_GET['path'] ?? '';
$url = $target . '/' . ltrim($path, '/');

$body = file_get_contents('php://input');
$method = $_SERVER['REQUEST_METHOD'];

$headers = ['Content-Type: application/json'];
$opts = [
    'http' => [
        'method' => $method,
        'header' => implode("\r\n", $headers),
        'content' => $body,
        'timeout' => 1800,
        'ignore_errors' => true,
    ]
];

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');

if ($method === 'OPTIONS') { http_response_code(204); exit; }

$result = file_get_contents($url, false, stream_context_create($opts));
header('Content-Type: application/json');
echo $result;
