summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-05-07 11:22:22 +0200
committerDaniel Weipert <code@drogueronin.de>2023-05-07 11:22:22 +0200
commit4ec19604ad82e90e5a758ab6b0a31654cdc66513 (patch)
tree229a437a611c2dea94dd64907cb5a8adf66d1d1f
parent1d121938f643737ca9de76286eef164c67f69482 (diff)
Fix json and cors request handlingHEADmain
-rw-r--r--Readme.md4
-rw-r--r--src/App.php10
2 files changed, 12 insertions, 2 deletions
diff --git a/Readme.md b/Readme.md
index bd67538..33663c6 100644
--- a/Readme.md
+++ b/Readme.md
@@ -3,7 +3,7 @@ Flat-File Forms
Forms and Submissions managed flat-file
-Callable via REST-API
+Callable via API
## Directory Structure
@@ -55,7 +55,7 @@ overwritten by config.yaml in $form/config/
included if exists in subsequent config folders
-## REST-API
+## API
`localhost:3000/$group/$group/$form`
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());