gpt4 book ai didi

javascript - Strapi v4 抛出 cors 异常

转载 作者:行者123 更新时间:2023-12-05 00:34:46 25 4
gpt4 key购买 nike

我是strapi的新手,我已经下载了strapi v4,作为前端我使用vue.js。
现在我创建了类别,并尝试使用我的 vue 应用程序获取这些类别,但我收到了一个 cors 错误。

Access to XMLHttpRequest at 'http://localhost:1337/api/categories' from origin 'http://localhost:8080' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
documentation我看到我可以覆盖 cors 中间件上的原点,但我不知道如何。
我已经用 resolve 试过了,然后设置了配置,但这会破坏 cms。
  {
resolve: 'strapi::cors',
config: {
origin: 'http://localhost:8080'
}
}

最佳答案

在互联网上花了几个小时后,我终于让它工作了。
在我的 config/middlewares.js我不得不更换 strapi::cors对此:

module.exports = [
...
{
name: 'strapi::cors',
config: {
enabled: true,
header: '*',
origin: ['http://localhost:8080']
}
}
...
];
不要忘记添加端口号,否则将无法正常工作。

关于javascript - Strapi v4 抛出 cors 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70639958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com