访问被 CORS 策略阻止 请求的资源上不存在“Access-Control-Allow-Origin”标头

问题描述 投票:0回答:1

Laravel 9.19

Livewire 2.10

灯丝2.0

masbug/flysystem-google-drive-ext 2.2

我正在尝试使用谷歌驱动器作为

filesystems
存储..一切正常,因此我可以存储文件并打开它..除了
filament
无法获取存储的文件并且控制台日志给我一个错误

文件系统.php

    'google' => [
      'driver' => 'google',
      'clientId' => "xxxxxxxxxxxx.apps.googleusercontent.com",
      'clientSecret' => "xxxxxxxxxxxxxxxxxxxxx",
      'refreshToken' => "xxxxxxxxxxxxxxxxxxxxxx",
      'folderId' => env('GOOGLE_DRIVE_FOLDER_ID', null),
    ],

配置/cors.php


<?php

return [

  'paths' => ['api/*'], //try ['api/*', 'oauth/*'] , [] and ['*'] Nothing work

  'allowed_methods' => ['*'],

  'allowed_origins' => ['*'],

  'allowed_origins_patterns' => [], //try ['*'] Not working

  'allowed_headers' => ['*'],

  'exposed_headers' => [],

  'max_age' => 0,

  'supports_credentials' => false, //try true Not working
];

投诉资源.php


public static function form(Form $form): Form
  {
    return $form
      ->schema([


        Section::make('')
          ->schema([
            //.........

            FileUpload::make('reply_pdf')
              ->disk('google')
              ->acceptedFileTypes(['application/pdf']),
            //.......

          ])->columns(3)
      ]);
  }

灯丝输入一直显示加载指示灯

控制台.log

我正在尝试制作一个中间件来解决这个问题..但什么也没发生

中间件/Cors.php

    public function handle(Request $request, Closure $next)
    {
      $response = $next($request);

      $response->headers->set('Access-Control-Allow-Origin', '*');
      $response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE');
      $response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');

      return $response;
    }

我尝试将下一个代码添加到 .htaccess 文件..但它也不起作用

.htaccess

    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
  • 我运行 php artisan config:clear 和 php artisan cache:clear .. 不工作

在 Chrome 浏览器中安装 CORS Unblock 扩展程序并从中启用 Access-Control-Allow-Origin 后唯一有效!

laravel-9 flysystem-google-drive laravel-filament
1个回答
0
投票

这只是一个评论,以防有人和我犯同样的愚蠢错误,我在 Laravel 中的 CORS 问题是因为我使用 127.0.0.1:8000 URL 而不是 localhost:8000。

© www.soinside.com 2019 - 2024. All rights reserved.