我是 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.
In the 文档我发现我可以覆盖 cors 中间件上的 origin,但我不知道如何实现。
我已经尝试过使用resolve,然后设置配置,但这会破坏cms。
{
resolve: 'strapi::cors',
config: {
origin: 'http://localhost:8080'
}
}
在互联网上花了几个小时后,我终于成功了。
In my config/middlewares.js
我不得不更换strapi::cors
对此:
module.exports = [
...
{
name: 'strapi::cors',
config: {
enabled: true,
header: '*',
origin: ['http://localhost:8080']
}
}
...
];
不要忘记添加端口号,否则将无法工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)