我正在嘗試制作一個簡單的注冊表單(只是在學習),但我遇到了 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
提交
取消