Fix proxy

This commit is contained in:
philipp lang 2024-06-26 17:00:23 +02:00
parent 88a57252ed
commit 061b4a84c1
1 changed files with 8 additions and 5 deletions

View File

@ -20,13 +20,13 @@ class Proxy
protected function get(string $url): ?array
{
$response = Http::acceptJson()->get($this->url($url));
$response = Http::header('Accept', 'application/json')->get($this->url($url));
if (!$response->ok()) {
if (!$response->ok) {
return null;
}
return $response->json();
return json_decode($response->body, true);
}
public function submit(string $url): JsonResponse
@ -36,9 +36,12 @@ class Proxy
'Authorization' => 'Bearer ' . request()->header('X-Adrema-Token'),
]
: [];
$response = Http::acceptJson()->withHeaders($headers)->post($this->url($url), request()->input());
$response = Http::make($this->url($url), 'POST')
->setOption(CURLOPT_POSTFIELDS, json_encode(request()->input()))
->header([...$headers, 'Accept' => 'application/json', 'Content-Type' => 'application/json'])
->send();
return response()->json($response->json(), $response->status());
return response()->json(json_decode($response->body, true), $response->code);
}
private function url(string $internal): string