当我想在 next 中使用 https://tenancyforlaravel.com/ 时出现 cors 错误

问题描述 投票:0回答:1

我正在 Laravel 11 中尝试使用 nextJS 的多租户应用程序作为前端,并面临这个问题 当我想用的时候

 const response = await axios.post<LoginResponse>(
        "http://test1.localhost:8000/login",
        {
          email,
          password,
        }
      );

它给了我cors错误

从源“http://localhost:3000”访问“http://test1.localhost:8000/login”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否“ Access-Control-Allow-Origin' 标头存在于请求的资源上。

但是当我向 http://localhost:8000 发送请求时它工作正常

php laravel next.js
1个回答
0
投票

我通过在 cors.php 中的路由中添加登录解决了问题

返回[

/*
|--------------------------------------------------------------------------
| 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/*','login', 'sanctum/csrf-cookie'],

'allowed_methods' => ['*'],

'allowed_origins' => ['*'],

'allowed_origins_patterns' => [],

'allowed_headers' => ['*'],

'exposed_headers' => [],

'max_age' => 0,

'supports_credentials' => false,

];

© www.soinside.com 2019 - 2024. All rights reserved.