实时服务器上的删除功能出现 CORS 错误:可以在本地工作,但不能在实时 Laravel 网站上工作

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

我正在开发一个 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 localhost backend webserver
1个回答
0
投票

安装 Laravel CORS 包

 composer require fruitcake/laravel-cors

发布配置文件
php artisan vendor:publish --tag="cors"

更新 config/cors.php 以包含您的实时域
'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

希望这会起作用

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