增加跨域支持
This commit is contained in:
parent
f0fee5ab58
commit
eb9ef828c3
5
application/middleware.php
Normal file
5
application/middleware.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
// 跨域处理
|
||||||
|
\app\common\middleware\CORS::class,
|
||||||
|
];
|
@ -25,30 +25,27 @@ class Auth
|
|||||||
*/
|
*/
|
||||||
public function handle($request, \Closure $next)
|
public function handle($request, \Closure $next)
|
||||||
{
|
{
|
||||||
$Origin = $request->header('Origin');
|
// $Origin = $request->header('Origin');
|
||||||
$Headers = $request->header('Access-Control-Request-Headers');
|
// $Headers = $request->header('Access-Control-Request-Headers');
|
||||||
header('Access-Control-Allow-Origin: ' . $Origin);
|
// header('Access-Control-Allow-Origin: ' . $Origin);
|
||||||
header('Access-Control-Allow-Headers: ' . $Headers);
|
// header('Access-Control-Allow-Headers: ' . $Headers);
|
||||||
header('Access-Control-Allow-Credentials:true');
|
// header('Access-Control-Allow-Credentials:true');
|
||||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
|
// header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
|
||||||
header('Access-Control-Max-Age: 1728000');
|
// header('Access-Control-Max-Age: 1728000');
|
||||||
header('Content-Type:text/plain charset=UTF-8');
|
// header('Content-Type:text/plain charset=UTF-8');
|
||||||
|
//
|
||||||
if (strtoupper($request->method()) == "OPTIONS") {
|
// if (strtoupper($request->method()) == "OPTIONS") {
|
||||||
header('HTTP/1.0 204 No Content');
|
// header('HTTP/1.0 204 No Content');
|
||||||
header('Content-Length:0');
|
// header('Content-Length:0');
|
||||||
header('status:204');
|
// header('status:204');
|
||||||
exit();
|
// exit();
|
||||||
}
|
// }
|
||||||
list($module, $controller, $action) = [$request->module(), $request->controller(), $request->action()];
|
list($module, $controller, $action) = [$request->module(), $request->controller(), $request->action()];
|
||||||
$access = $this->buildAuth($node = NodeService::parseNodeStr("{$module}/{$controller}/{$action}"));
|
$access = $this->buildAuth($node = NodeService::parseNodeStr("{$module}/{$controller}/{$action}"));
|
||||||
$currentOrganizationCode = $request->header('organizationCode');
|
$currentOrganizationCode = $request->header('organizationCode');
|
||||||
if ($currentOrganizationCode) {
|
if ($currentOrganizationCode) {
|
||||||
session('currentOrganizationCode', $currentOrganizationCode);
|
session('currentOrganizationCode', $currentOrganizationCode);
|
||||||
}
|
}
|
||||||
// var_dump(session_id());
|
|
||||||
// die;
|
|
||||||
|
|
||||||
// 登录状态检查
|
// 登录状态检查
|
||||||
if (!empty($access['is_login']) && !session('member')) {
|
if (!empty($access['is_login']) && !session('member')) {
|
||||||
$msg = ['code' => 401, 'msg' => '抱歉,您还没有登录获取访问权限!'];
|
$msg = ['code' => 401, 'msg' => '抱歉,您还没有登录获取访问权限!'];
|
||||||
|
@ -6,7 +6,7 @@ return [
|
|||||||
// 应用名称
|
// 应用名称
|
||||||
'app_name' => 'pearProject',
|
'app_name' => 'pearProject',
|
||||||
// 应用版本
|
// 应用版本
|
||||||
'app_version' => '2.0.0',
|
'app_version' => '2.0.0',
|
||||||
// 应用地址
|
// 应用地址
|
||||||
'app_host' => '',
|
'app_host' => '',
|
||||||
// 应用调试模式
|
// 应用调试模式
|
||||||
|
Loading…
x
Reference in New Issue
Block a user