AllowCrossDomain.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\api\middleware;
  12. use app\Request;
  13. use Closure;
  14. /**
  15. * http跨域请求中间件
  16. * Class AllowCrossDomain
  17. * @package app\api\middleware
  18. */
  19. class AllowCrossDomain
  20. {
  21. public function handle(Request $request, Closure $next)
  22. {
  23. $allow_header = [
  24. system_name('api_token_name'),
  25. system_name('channel_name'),
  26. 'lang',
  27. '*'
  28. ];
  29. header("Access-Control-Allow-Headers: Authorization, Sec-Fetch-Mode, DNT, X-Mx-ReqToken, Keep-Alive, User-Agent, If-Match, If-None-Match, If-Unmodified-Since, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Accept-Language, Origin, Accept-Encoding,Access-Token,version,".implode(',', $allow_header));
  30. header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
  31. header('Access-Control-Max-Age: 1728000');
  32. header('Access-Control-Allow-Credentials:true');
  33. header('Access-Control-Allow-Origin: *');
  34. return $next($request);
  35. }
  36. }