在中间件处理
public function handle($request, Closure $next)
{
$response = $next($request);
$allowOrigin = [
'http://aaa.com',
'http://bbb.com',
];
if (in_array($request->header('origin'), $allowOrigin)) {
//$response->header("Access-Control-Allow-Origin","*");
$response->header("Access-Control-Allow-Origin", $request->header('origin'));
}
$response->header("Access-Control-Allow-Credentials", 'true');
$response->header('Access-Control-Allow-Methods', "GET,POST,OPTIONS");
$response->header("Access-Control-Allow-Headers", "*");
return $response;
}