From 5a37b2c6493573ca087db0d5ecac6a310fd678c7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 9 Feb 2022 18:10:21 +0100 Subject: [PATCH] Fix API call --- htdocs/api/index.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index da194f12655..ae84e61ea32 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -61,6 +61,13 @@ if (preg_match('/\/explorer\/swagger\.json/', $_SERVER["PHP_SELF"])) { header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); header('Access-Control-Allow-Headers: Content-Type, Authorization, api_key, DOLAPIKEY'); } +// When we request url to get an API, we accept Cross site so we can make js API call inside another website +if (preg_match('/\/api\/index\.php/', $_SERVER["PHP_SELF"])) { + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE'); + header('Access-Control-Allow-Headers: Content-Type, Authorization, api_key, DOLAPIKEY'); +} + $res = 0; if (!$res && file_exists("../main.inc.php")) {