$db->query("SELECT value FROM settings WHERE key = 'relay_url'")->fetchColumn() ?: '', 'user' => $db->query("SELECT value FROM settings WHERE key = 'relay_username'")->fetchColumn() ?: '', 'key' => $db->query("SELECT value FROM settings WHERE key = 'relay_key'")->fetchColumn() ?: '', ]; } PluginManager::instance()->onApiRoute(function (string $route, string $method) { if ($route !== '/api/shopping' && $route !== '/api/shopping/check') return; if (!in_array($method, ['GET', 'POST'], true)) return; $r = shoppingRelay(); if (!$r['url'] || !$r['user'] || !$r['key']) { shoppingJson(['ok' => false, 'error' => 'relay not configured']); } $ch = curl_init(rtrim($r['url'], '/') . $route); $opts = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'X-Relay-User: ' . $r['user'], 'X-Relay-Key: ' . $r['key'], ], CURLOPT_TIMEOUT => 10, ]; if ($method === 'POST') { $opts[CURLOPT_POST] = true; $opts[CURLOPT_POSTFIELDS] = file_get_contents('php://input') ?: '{}'; } curl_setopt_array($ch, $opts); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); http_response_code($status ?: 502); header('Content-Type: application/json'); echo is_string($response) ? $response : json_encode(['ok' => false, 'error' => 'relay unreachable']); exit; });