浏览代码

NEW The swagger.json file of API can be included into external sources

Laurent Destailleur 4 年之前
父节点
当前提交
8dd07fb6d5
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      htdocs/api/index.php

+ 6 - 0
htdocs/api/index.php

@@ -55,6 +55,12 @@ if (!empty($_SERVER['HTTP_DOLAPIENTITY'])) {
 	define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']);
 }
 
+// When we request url to get the json file, we accept Cross site so we can include the descriptor into an external tool.
+if (preg_match('/\/explorer\/swagger\.json/', $_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")) {