Ref*_*lon 5 javascript cors strapi
我是 Strapi 的新手,我已经下载了 Strapi v4,并且我使用 vue.js 作为前端。
\n现在我创建了类别,并尝试使用我的 vue 应用程序获取这些类别,但我\xe2\x80\x99m 收到 cors 错误。
\nAccess 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.\nRun Code Online (Sandbox Code Playgroud)\n在文档中中,我看到我可以覆盖 cors 中间件上的原点,但我不知道怎么做。
\n我\xe2\x80\x99已经尝试过解析,然后设置配置,但这破坏了cms。
\n {\n resolve: \'strapi::cors\',\n config: {\n origin: \'http://localhost:8080\'\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n
在互联网上花了几个小时后,我终于成功了。
在我中config/middlewares.js,我必须替换strapi::cors为:
module.exports = [
...
{
name: 'strapi::cors',
config: {
enabled: true,
header: '*',
origin: ['http://localhost:8080']
}
}
...
];
Run Code Online (Sandbox Code Playgroud)
不要忘记添加端口号,否则将无法工作。
| 归档时间: |
|
| 查看次数: |
8151 次 |
| 最近记录: |