增加跨域支持
This commit is contained in:
parent
4646375db5
commit
fe1972c6f6
38
application/common/middleware/CORS.php
Normal file
38
application/common/middleware/CORS.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\middleware;
|
||||
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 跨域处理
|
||||
* Class Auth
|
||||
* @package app\admin\middleware
|
||||
*/
|
||||
class CORS
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
|
||||
$Origin = $request->header('Origin');
|
||||
$Headers = $request->header('Access-Control-Request-Headers');
|
||||
header('Access-Control-Allow-Origin: ' . $Origin);
|
||||
header('Access-Control-Allow-Headers: ' . $Headers);
|
||||
header('Access-Control-Allow-Credentials:true');
|
||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||
header('Access-Control-Max-Age: 1728000');
|
||||
header('Content-Type:text/plain charset=UTF-8');
|
||||
if (strtoupper($request->method()) == "OPTIONS") {
|
||||
header('HTTP/1.0 204 No Content');
|
||||
header('Content-Length:0');
|
||||
header('status:204');
|
||||
exit();
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -25,21 +25,6 @@ class Auth
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
// $Origin = $request->header('Origin');
|
||||
// $Headers = $request->header('Access-Control-Request-Headers');
|
||||
// header('Access-Control-Allow-Origin: ' . $Origin);
|
||||
// header('Access-Control-Allow-Headers: ' . $Headers);
|
||||
// header('Access-Control-Allow-Credentials:true');
|
||||
// header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
|
||||
// header('Access-Control-Max-Age: 1728000');
|
||||
// header('Content-Type:text/plain charset=UTF-8');
|
||||
//
|
||||
// if (strtoupper($request->method()) == "OPTIONS") {
|
||||
// header('HTTP/1.0 204 No Content');
|
||||
// header('Content-Length:0');
|
||||
// header('status:204');
|
||||
// exit();
|
||||
// }
|
||||
list($module, $controller, $action) = [$request->module(), $request->controller(), $request->action()];
|
||||
$access = $this->buildAuth($node = NodeService::parseNodeStr("{$module}/{$controller}/{$action}"));
|
||||
$currentOrganizationCode = $request->header('organizationCode');
|
||||
|
Loading…
x
Reference in New Issue
Block a user