Blame view

稻城亚丁小程序/backend/app/middleware/AllowCrossDomain.php 728 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  <?php
  declare(strict_types=1);
  
  namespace app\middleware;
  
  /**
   * H5 / 管理端跨域
   */
  class AllowCrossDomain
  {
      public function handle($request, \Closure $next)
      {
          $header = [
              'Access-Control-Allow-Origin'      => '*',
              'Access-Control-Allow-Methods'     => 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
              'Access-Control-Allow-Headers'     => 'Authorization, Content-Type, Accept, Accept-Language, X-Client-Id, X-Requested-With',
              'Access-Control-Max-Age'           => '86400',
          ];
  
          if (strtoupper($request->method()) === 'OPTIONS') {
              return response('', 204)->header($header);
          }
  
          return $next($request)->header($header);
      }
  }