AllowCrossDomain.php
728 Bytes
<?php
declare(strict_types=1);
namespace app\middleware;
/**
* H5 / 管理端跨域
*/
class AllowCrossDomain
{
public function handle($request, \Closure $next)
{
$header = [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, Accept, Accept-Language, X-Client-Id, X-Requested-With',
'Access-Control-Max-Age' => '86400',
];
if (strtoupper($request->method()) === 'OPTIONS') {
return response('', 204)->header($header);
}
return $next($request)->header($header);
}
}