我正在 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 发送请求时它工作正常
我通过在 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,
];