<?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>
// +----------------------------------------------------------------------

use think\App;
require __DIR__ . '/../vendor/autoload.php';
// 设置允许的跨域源，这里以 http://localhost:8080 为例，你可以根据实际情况修改
header( 'Access-Control-Allow-Origin: http://localhost:8082' );
// 设置允许的请求方法
header( 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS' );
// 设置允许的请求头部，包含 token 字段
// 增加 Authorization 字段，并建议加上 Content-Type
header( 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,token,Authorization' );
// 设置允许暴露的响应头部
header( 'Access-Control-Expose-Headers: Content-Length,Content-Range' );

// 处理预检请求
if ( $_SERVER[ 'REQUEST_METHOD' ] === 'OPTIONS' ) {
    // 设置预检请求的最大缓存时间
    header( 'Access-Control-Max-Age: 1728000' );
    // 设置响应内容类型
    header( 'Content-Type: text/plain; charset=utf-8' );
    // 设置响应内容长度
    header( 'Content-Length: 0' );
    // 返回 204 状态码表示请求已成功处理但没有内容返回
    http_response_code( 204 );
    exit;
}
// [ 应用入口文件 ]

require __DIR__ . '/../vendor/autoload.php';

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

$response = $http->run();

$response->send();

$http->end( $response );
