我正在尝试制作一个简单的注册表单(只是在学习),但我遇到了 CORS 问题。我已经尝试了所有我发现的东西,但没有一个起作用。据我所知,Laravel 7 已经可以防止 CORS 问题,但我的却不能。这是我的代码:api.php<?phpuse Illuminate\Http\Request;use Illuminate\Support\Facades\Route;/*|--------------------------------------------------------------------------| API Routes|--------------------------------------------------------------------------|| Here is where you can register API routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| is assigned the "api" middleware group. Enjoy building your API!|*/Route::group([ 'prefix' => 'auth',], function () { Route::post('login', 'AuthController@login'); Route::post('signup', 'AuthController@signup'); Route::group([ 'middleware' => 'auth:api' ], function () { Route::get('logout', 'AuthController@logout'); Route::get('user', 'AuthController@user'); });});Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user();});cors.php<?phpreturn [ /* |-------------------------------------------------------------------------- | 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,];
添加回答
举报
0/150
提交
取消