【发布时间】:2020-12-05 04:37:16
【问题描述】:
nuxt 和 laravel 7 Route::group 的新手
更新在这里打开了一个问题:
https://github.com/fruitcake/laravel-cors/issues/487
我的 laravel 和 cors 包版本:
- "fruitcake/laravel-cors": "^2.0",
- "laravel/framework": "^7.24",
我的 Api 路由
Route::group(['prefix' => 'auth', 'namespace' => 'Auth'], function () {
Route::post('signin', 'SignInController');
Route::get('me', 'MeController');
Route::post('signout', 'SignOutController');
});
Route::group(['prefix' => 'snippets', 'namespace' => 'Snippets'], function () {
Route::post('', 'SnippetController@store');
Route::get('{snippet:uuid}', 'SnippetController@show');
});
auth 路由有效,但 sn-p 无效。
我的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' => ['api/*', 'api/snippets', '*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['http://localhost:3000'],
'allowed_origins_patterns' => ['*'],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
我也试过了
<?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' => ['api/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => ['*'],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
在每次重试之前,我都使用了php artisan config:cache 命令。
Cors 错误
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/api/snippets. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
这个请求http://localhost:8000/api/snippets/ 在邮递员中可以正常工作,但在 nuxt 中不行,我得到了 cors 错误。
谁能告诉我这里发生了什么?
谢谢
【问题讨论】: