Blame view

天文台pc/daocheng-api/app/middleware/Cors.php 917 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  <?php
  declare(strict_types=1);
  
  namespace app\middleware;
  
  use Closure;
  use think\Request;
  use think\Response;
  
  class Cors
  {
      public function handle(Request $request, Closure $next): Response
      {
          $origin = $request->header('origin', '*');
          $header = [
              'Access-Control-Allow-Origin'      => $origin ?: '*',
              'Access-Control-Allow-Methods'     => 'GET, POST, PUT, OPTIONS, DELETE',
3a3dc915   王天杨   feat: 稻城亚丁项目批量更新
18
              'Access-Control-Allow-Headers'     => 'Content-Type, Authorization, X-Admin-Token, X-Requested-With',
bc518174   王天杨   提交两个项目文件
19
20
21
22
23
24
25
26
27
28
29
              'Access-Control-Allow-Credentials' => 'true',
              'Access-Control-Max-Age'           => '86400',
          ];
          if (strtoupper($request->method()) === 'OPTIONS') {
              return response('', 204)->header($header);
          }
          /** @var Response $response */
          $response = $next($request);
          return $response->header($header);
      }
  }