我最近将我的Laravel应用上传到了VPS水果蛋糕/ laravel-cors软件包。 我的配置是:
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' => ['api/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['http://dash.site.ca'],
'allowed_origins_patterns' => [],
'allowed_headers' => [
'Content-Type',
'Accept',
'Authorization',
'X-Requested-With',
'Application',
'api_key'
],
'exposed_headers' => false,
'max_age' => false,
'supports_credentials' => false,
];
I enable apache2 header, I have a request that has a custom header named api_key
but I can not get my custom header in Laravel middleware like so :
$request->header('api_key')
此代码在本地有效,但在服务器上没有运气。除了我的自定义标题外,我正在获取所有标题。当我尝试在.htaccess文件中设置cors策略时,cors完全不起作用。
Header add Access-Control-Allow-Origin "http://dash.site.ca"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"