Skip to content

Commit

Permalink
try to make RegionalData cors compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Apr 29, 2024
1 parent 4332349 commit 39a03a5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions LitCalRegionalData.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class LitCalRegionalData {
private object $RESPONSE;
//The General Index is currently only used for diocesan calendars
private ?stdClass $GeneralIndex = null;
private array $AllowedRequestMethods = [ 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS' ];

public APICore $APICore;

Expand All @@ -65,9 +66,14 @@ private function handleRequestedMethod() {
$this->handlePutPatchDeleteRequests( RequestMethod::DELETE );
break;
case RequestMethod::OPTIONS:
//continue;
break;
default:
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
header("Access-Control-Allow-Methods: " . implode( ', ', $this->AllowedRequestMethods ));
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}
continue;
default:
header( $_SERVER[ "SERVER_PROTOCOL" ]." 405 Method Not Allowed", true, 405 );
$errorMessage = '{"error":"You seem to be forming a strange kind of request? Allowed Request Methods are ';
$errorMessage .= implode( ' and ', $this->AllowedRequestMethods );
Expand Down

0 comments on commit 39a03a5

Please sign in to comment.