43 lines
850 B
PHP
43 lines
850 B
PHP
<?php
|
|
/**
|
|
* 处理OPTIONS预检请求的中间件
|
|
*
|
|
* User: system
|
|
* Date: 2024/06/18
|
|
**/
|
|
|
|
namespace app\api\middleware;
|
|
|
|
class OptionsRequestMiddleware
|
|
{
|
|
/**
|
|
* 处理OPTIONS预检请求
|
|
*
|
|
* @param \think\Request $request
|
|
* @param \Closure $next
|
|
* @return \think\Response
|
|
*/
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
// 处理OPTIONS预检请求
|
|
if (strtoupper($request->method()) == "OPTIONS") {
|
|
exit;
|
|
}
|
|
|
|
// 继续执行下一个中间件
|
|
$response = $next($request);
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* 中间件结束调度
|
|
*
|
|
* @param \think\Response $response
|
|
* @return void
|
|
*/
|
|
public function end(\think\Response $response)
|
|
{
|
|
// 可以在这里对响应做额外处理
|
|
}
|
|
}
|