合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
>[info] 跨域中间件 ~~~ <?php declare (strict_types=1); namespace app\admin\middleware; class Cross { /** * 处理请求 * * @param \think\Request $request * @param \Closure $next * @return Response */ public function handle($request, \Closure $next) { $response = $next($request); $origin = $request->header('Origin', ''); // OPTIONS请求返回204请求 if ($request->method(true) === 'OPTIONS') { $response->code(204); } $response->header([ 'Access-Control-Allow-Origin' => $origin, 'Access-Control-Allow-Methods' => 'GET,POST,PUT', 'Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Headers' => '*', ]); return $response; } } ~~~