From 43d2879aed239608c626f9d4d20825c901180ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Sat, 6 Aug 2022 23:30:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=94=BE=E8=A1=8C=E6=89=80=E6=9C=89option?= =?UTF-8?q?s=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/index.php b/public/index.php index f911a965..5468af68 100644 --- a/public/index.php +++ b/public/index.php @@ -16,10 +16,17 @@ namespace think; * 不在tp加载后判断,为了安全的使用exit() * 使用绝对路径,确保花里胡哨的url均能正确判定和跳转 */ +if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { + header("Access-Control-Allow-Credentials: true"); + header("Access-Control-Max-Age: 86400"); + header("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS"); + header("Access-Control-Allow-Headers: " . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']); + header("Access-Control-Allow-Origin: *"); + exit(); +} + $rootPath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR; - -$server = isset($_REQUEST['server']) || isset($_SERVER['HTTP_SERVER']) || substr($_SERVER['REQUEST_URI'], 1, 9) == 'index.php'; - +$server = isset($_REQUEST['server']) || isset($_SERVER['HTTP_SERVER']) || substr($_SERVER['REQUEST_URI'], 1, 9) == 'index.php'; if (!$server) { // 用户访问前端