更新
This commit is contained in:
@@ -12,7 +12,6 @@ namespace app\middleware;
|
||||
|
||||
use think\Config;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
|
||||
class AllowCrossDomain{
|
||||
|
||||
@@ -36,6 +35,7 @@ class AllowCrossDomain{
|
||||
* @return Response
|
||||
*/
|
||||
public function handle($request, \Closure $next, ? array $header = []){
|
||||
$response = $next($request);
|
||||
$header = !empty($header) ? array_merge($this->header, $header) : $this->header;
|
||||
|
||||
if (!isset($header['Access-Control-Allow-Origin'])) {
|
||||
@@ -43,6 +43,10 @@ class AllowCrossDomain{
|
||||
$header['Access-Control-Allow-Origin'] = $origin ? $origin : "*";
|
||||
}
|
||||
|
||||
return $next($request)->header($header);
|
||||
if (strtoupper($request->method()) == "OPTIONS") {
|
||||
$response->code(204);
|
||||
}
|
||||
|
||||
return $response->header($header);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user