Axios.defaults.withCredentials = true 使 api 响应瘫痪

Axios.defaults.withCredentials = true paralyzes api response

我已经完成了 laravel、nuxt(ssr,server) 项目并将它们部署在单独的子域中,例如 api.example.com && beta.example.com.

为了用户登录,当我将 axios.defaults.withCredentials = true 添加到 laravel 中的 resources/js/bootstrap.js 文件时,所有 api get/post 请求变得如此缓慢甚至请求抛出超时,但是当我直接连接到 api url 时,如 https://api.example.com/api/v1/categories 它会立即显示。此外,在 beta 子域中,无需使用 axios.defaults.withCredentials = true.

我在 nuxt 中使用 laravel sanctum 和 @nuxtjs/proxy 模块,例如:

nuxt.config.js

modules: [
    // https://go.nuxtjs.dev/axios
    ['@nuxtjs/axios', {
        proxy: true,
        credentials: true,
    }],
    // https://github.com/nuxt-community/proxy-module
    '@nuxtjs/proxy',
],
proxy: {
    "/v1/": {
        target: `https://api.example.com/api/v1`,
        pathRewrite: { "^/v1": "" },
        changeOrigin: true
    },
    // and more
    // ...
    // ..
    // .
},

cors.php

  'paths' => [
    'api/*',
    'login',
    'logout',
    'register',
    'forgot-password',
    'reset-password',
    'user/password',
    'user/profile-information',
    'email/verify/*',
    'email/verification-notification',
    'sanctum/csrf-cookie',
],

'allowed_methods' => ['*'],

'allowed_origins' => ['*'],

'allowed_origins_patterns' => [],

'allowed_headers' => ['*'],

'exposed_headers' => [],

'max_age' => 0,

'supports_credentials' => true,

bootstrap.js

axios.defaults.withCredentials = true;

.env

SESSION_DRIVER=cookie
SESSION_DOMAIN=.example.com
SANCTUM_STATEFUL_DOMAINS=*.example.com

为什么axios.defaults.withCredentials = true那样做?我不知道是什么导致了这种减速...我该怎么做才能解决这个问题?

window.axios.defaults.withCredentials = true;