前端目录调整
This commit is contained in:
48
app/middleware/AllowCrossDomain.php
Normal file
48
app/middleware/AllowCrossDomain.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use think\Config;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
|
||||
class AllowCrossDomain{
|
||||
|
||||
protected $header = [
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Max-Age' => 1800,
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',
|
||||
];
|
||||
|
||||
public function __construct(Config $config){
|
||||
$this->header = array_merge($this->header, $config->get('cross', ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* 允许跨域请求
|
||||
* @access public
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param array $header
|
||||
* @return Response
|
||||
*/
|
||||
public function handle($request, \Closure $next, ? array $header = []){
|
||||
$header = !empty($header) ? array_merge($this->header, $header) : $this->header;
|
||||
|
||||
if (!isset($header['Access-Control-Allow-Origin'])) {
|
||||
$origin = $request->header('origin');
|
||||
$header['Access-Control-Allow-Origin'] = $origin ? $origin : "*";
|
||||
}
|
||||
|
||||
return $next($request)->header($header);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,9 @@ declare (strict_types = 1);
|
||||
namespace app\middleware;
|
||||
|
||||
class Api{
|
||||
|
||||
public $data = ['code' => 1, 'data' => '', 'message' => ''];
|
||||
|
||||
/**
|
||||
* 处理请求
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user