Update plugin.php

Added full CORS policy and OPTIONS method to allow API call from JavaScript
This commit is contained in:
Dimo 2021-01-01 13:50:37 +02:00 committed by GitHub
parent 5abddff1aa
commit f1639a2646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -69,6 +69,14 @@ class pluginAPI extends Plugin {
// ------------------------------------------------------------
$method = $this->getMethod();
// Added full CORS policy and OPTIONS method to allow API call from JS
if ($method === 'OPTIONS'){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, HEAD, OPTIONS, POST, PUT');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
exit;
}
// METHOD INPUTS
// ------------------------------------------------------------
$inputs = $this->getMethodInputs();