diff --git a/juggl-server/api/services/apiBranch.inc.php b/juggl-server/api/services/apiBranch.inc.php index 6e91e72..4c38820 100644 --- a/juggl-server/api/services/apiBranch.inc.php +++ b/juggl-server/api/services/apiBranch.inc.php @@ -13,6 +13,11 @@ abstract class ApiBranch { function execute ($authenticationRequired = true) { $params = $this->getParams(); + + $currentType = currentRequestType(); + if ($currentType === RequestType::OPTIONS) { + respondStatus(200); + } if ($authenticationRequired) { $auth = new Authenticator(); @@ -22,16 +27,23 @@ abstract class ApiBranch { } } - $currentType = currentRequestType(); - if($currentType === RequestType::GET) { + if ($currentType === RequestType::GET) { $this->get($params); } else if ($currentType === RequestType::POST) { $this->post($params); } + if ($currentType === RequestType::GET) { + $this->get($params); + } else if ($currentType === RequestType::POST) { + $this->post($params); + } else { + respondStatus(405); + } } private function getParams() { $content = json_decode(file_get_contents('php://input'), true); + if ($content == NULL) $content = array(); return new ParamCleaner(array_merge($content, $_REQUEST, $_SESSION, $_FILES)); } } diff --git a/juggl-server/api/services/requestTypes.inc.php b/juggl-server/api/services/requestTypes.inc.php index 786562f..eef2894 100644 --- a/juggl-server/api/services/requestTypes.inc.php +++ b/juggl-server/api/services/requestTypes.inc.php @@ -6,6 +6,7 @@ abstract class RequestType extends BasicEnum { const POST = "POST"; const PUT = "PUT"; const DELETE = "DELETE"; + const OPTIONS = "OPTIONS"; } function currentRequestType () { diff --git a/juggl-server/api/services/responses.inc.php b/juggl-server/api/services/responses.inc.php index a9c6962..47d63d6 100644 --- a/juggl-server/api/services/responses.inc.php +++ b/juggl-server/api/services/responses.inc.php @@ -1,16 +1,29 @@ getJson()); } -function respondHtml(string $html) { +function respondHtml(string $html) +{ + defaultHeader(); print($html); } -function respondStatus(int $statusCode, string $message = "") { +function respondStatus(int $statusCode, string $message = "") +{ + defaultHeader(); http_response_code($statusCode); die($message); }