feat(api): 添加 CORS headers 支持跨域访问(UniApp 直连)
parent
683dee75dc
commit
9617f5c4c0
|
|
@ -21,6 +21,10 @@ require __DIR__ . '/../vendor/autoload.php';
|
||||||
// 执行HTTP应用并响应
|
// 执行HTTP应用并响应
|
||||||
$http = (new App())->http;
|
$http = (new App())->http;
|
||||||
$response = $http->name('api')->run();
|
$response = $http->name('api')->run();
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||||
|
header('Access-Control-Allow-Headers: DNT,User-Agent,Cache-Control,Content-Type,ajax,Authorization,token');
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(204); exit; }
|
||||||
$response->send();
|
$response->send();
|
||||||
$http->end($response);
|
$http->end($response);
|
||||||
?>
|
?>
|
||||||
Loading…
Reference in New Issue