我是一个前端是React JS,后端是Laravel的应用程序。这两个都是使用Plesk部署的。我已经在Laravel后端设置了所有必要的配置来处理CORS问题。但它仍然给CORS错误。
下面是laravel后端的config文件夹中的cors.php文件的内容。
return [
/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your settings for cross-origin resource sharing
| or "CORS". This determines what cross-origin operations may execute
| in web browsers. You are free to adjust these settings as needed.
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
*/
'paths' => ['*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['url_of_react_app'],
'allowed_origins_patterns' => ['*'],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
它仍然抛出CORS错误。Laravel后端和react应用程序都是通过https进行的。CORS错误是这样的。
CORS策略已阻止从源“URL_of_React_app”访问“URL_of_laravel_backend”处的XMLHttpRequest:对印前检查请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
React app中的API配置是这样的
import axios from "axios";
export const baseURL = "URL_of _laravel_backend";
export const axiosPublicInstance = axios.create({
baseURL,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
},
});
1条答案
按热度按时间wvt8vs2t1#
例如,你可以将url添加到“路径”键中,