<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]
namespace think;
require __DIR__ . '/../vendor/autoload.php';

// var_dump($_SERVER['REQUEST_METHOD']);
//.. 跨 域问 题
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    // 允许 跨域请求的域名
    allowCrossDomain01();
    echo '跨域成功';
    exit;
}

// 允许 跨域请求的域名
function allowCrossDomain01()
{
  // 允许  跨  域请 求 的域 名
    $originarr = [
        'http://192.168.1.165:8080',
        'http://localhost:5173',
        'http://localhost:8080',
        'http://192.168.1.193:8080',
        'http://192.168.3.31:8080',
        'http://ph5.miaoyinbao.com'

          
    ];
  // 获取当前跨域域名
  $origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
  if (in_array($origin, $originarr)) {
      // 允许 $originarr 数组内的 域名跨域访问
      //header('Access-Control-Allow-Origin:' . $origin);
      header('Access-Control-Allow-Origin: * ');
      // 响应类型
      header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
      // 带 cookie 的跨域访问
      header('Access-Control-Allow-Credentials: true');
      // 响应头设置
      header('Access-Control-Allow-Headers: Priority,servertoken,token, Authorization, Origin, Accept, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With');

    }
}
//...  跨域








// 执行HTTP应用并响应
$http = (new App())->http;

$response = $http->run();

$response->send();

$http->end($response);
