From 4ec19604ad82e90e5a758ab6b0a31654cdc66513 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 7 May 2023 11:22:22 +0200 Subject: Fix json and cors request handling --- src/App.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/App.php b/src/App.php index 7a0c28d..ab5c592 100644 --- a/src/App.php +++ b/src/App.php @@ -64,6 +64,11 @@ class App } } + // support "Content-Type: application/json" + if ($request->headers->get('Content-Type') == 'application/json') { + $_POST = $request->toArray(); + } + // check api key $apiKey = $_GET['key'] ?? $_POST['key'] ?? null; if (empty($apiKey)) { @@ -134,6 +139,11 @@ class App } } } + + // OPTIONS + else if ($method == 'OPTIONS') { + $response->headers->set('Access-Control-Allow-Headers', $request->headers->get('Access-Control-Request-Headers')); + } } catch (\Exception $exception) { if ($exception instanceof HttpException) { $response->setStatusCode($exception->getCode()); -- cgit v1.2.3