我正在开发一个 Laravel 项目,用户可以通过仪表板删除评论。删除功能在本地主机中完美运行,但将应用程序部署到我的实时服务器(InfinityFree)后,我在尝试删除评论时遇到了 CORS 错误。
网站:[http://book-reviews.lovestoblog.com/]1
问题:当用户尝试从仪表板删除评论时,会发生以下 CORS 错误:
my-reviews:1 Access to XMLHttpRequest at 'https://errors.infinityfree.net/errors/403/' (redirected from 'http://book-reviews.lovestoblog.com/account/delete-myreview') from origin 'http://book-reviews.lovestoblog.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.Understand this error
jquery-3.7.1.min.js:2
DELETE https://errors.infinityfree.net/errors/403/ net::ERR_FAILED
安装 Laravel CORS 包
composer require fruitcake/laravel-cors
php artisan vendor:publish --tag="cors"
'paths' => ['api/*', 'account/delete-myreview'],
'allowed_methods' => ['*'],
'allowed_origins' => ['http://book-reviews.lovestoblog.com'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
php artisan config:cache
希望这会起作用