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

@ -68,6 +68,14 @@ class pluginAPI extends Plugin {
// METHOD
// ------------------------------------------------------------
$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
// ------------------------------------------------------------
@ -761,4 +769,4 @@ class pluginAPI extends Plugin {
'message'=>'Error moving the file to the final path.'
);
}
}
}