为了账号安全,请及时绑定邮箱和手机立即绑定

React + Laravel 7 API - CORS 问题

React + Laravel 7 API - CORS 问题

PHP
料青山看我应如是 2023-07-08 16:35:35
我正在尝试制作一个简单的注册表单(只是在学习),但我遇到了 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,];
查看完整描述

1 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

我通过在 axios 请求中添加“http://”解决了这个问题。



查看完整回答
反对 回复 2023-07-08
  • 1 回答
  • 0 关注
  • 111 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信