在Laravel 5.8上安装了水果蛋糕/ laravel-cors
我的测试服务器使用php artisan服务,使用route / api.php在127.0.0.1:8000上投放客户端(nuxt)在127.0.0.1:3000上运行
我可以使用POSTMAN工具将数据发送到服务器
我已经配置了fruitcake / laravel-cors
protected $middleware = [
// ...
\Fruitcake\Cors\HandleCors::class,
];
和config / cors.php
<?php
return [
/*
* You can enable CORS for 1 or multiple paths.
* Example: ['api/*']
*/
'paths' => [],
/*
* Matches the request method. `[*]` allows all methods.
*/
'allowed_methods' => ['*'],
/*
* Matches the request origin. `[*]` allows all origins.
*/
'allowed_origins' => ['*'],
/*
* Matches the request origin with, similar to `Request::is()`
*/
'allowed_origins_patterns' => [],
/*
* Sets the Access-Control-Allow-Headers response header. `[*]` allows all headers.
*/
'allowed_headers' => ['*'],
/*
* Sets the Access-Control-Expose-Headers response header.
*/
'exposed_headers' => false,
/*
* Sets the Access-Control-Max-Age response header.
*/
'max_age' => false,
/*
* Sets the Access-Control-Allow-Credentials header.
*/
'supports_credentials' => false,
];
仍然得到:
访问XMLHttpRequest在原产地为“ http://127.0.0.1:8000/api/customerFeedbackStore”“ http://127.0.0.1:3000”已被CORS政策阻止:否请求中存在“ Access-Control-Allow-Origin”标头资源。
在浏览器中。
'路径'不能为空。您至少应将其设置为['*'],以便涵盖所有请求。