app = $app; } /** * 处理请求 * * @param \think\Request $request * @param \Closure $next * @return Response */ public function handle($request, \Closure $next) { /** @var Response $response */ $response = $next($request); // 支持跨域请求的host数组['a.cn', 'b.cn'] $corsHost = ['api.ahbmz.com', 'cms.ahbmz.com','www.yaoli.com']; if (!empty($corsHost) && is_array($corsHost) && in_array($request->host(), $corsHost)) { $response->header([ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE', 'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match,token, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With', ]); } return $response; } }