图片服务器上传Api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.1 KiB

<?php
declare (strict_types=1);
namespace app\middleware;
use think\App;
class AllowCrossDomain
{
protected $app;
public function __construct(App $app)
{
$this->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;
}
}