44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* 处理跨域请求的中间件
|
|
*
|
|
* User: system
|
|
* Date: 2024/06/18
|
|
**/
|
|
|
|
namespace app\api\middleware;
|
|
|
|
class CorsMiddleware
|
|
{
|
|
/**
|
|
* 处理跨域请求
|
|
*
|
|
* @param \think\Request $request
|
|
* @param \Closure $next
|
|
* @return \think\Response
|
|
*/
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
// 处理跨域
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Max-Age: 1800');
|
|
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
|
|
header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With,access-token,token,client,platform,version,clickid,device,device_info,adid');
|
|
|
|
// 继续执行下一个中间件
|
|
$response = $next($request);
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* 中间件结束调度
|
|
*
|
|
* @param \think\Response $response
|
|
* @return void
|
|
*/
|
|
public function end(\think\Response $response)
|
|
{
|
|
// 可以在这里对响应做额外处理
|
|
}
|
|
}
|