From f1639a26469390b0007967178c2399d5f5fc450b Mon Sep 17 00:00:00 2001 From: Dimo Date: Fri, 1 Jan 2021 13:50:37 +0200 Subject: [PATCH] Update plugin.php Added full CORS policy and OPTIONS method to allow API call from JavaScript --- bl-plugins/api/plugin.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index ec5dc4c4..5357a380 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -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.' ); } -} \ No newline at end of file +}