【发布时间】:2022-06-18 21:35:58
【问题描述】:
我使用strapi 4作为本地主机,当我通过url添加新资产时遇到cors设置问题
图片上传出现CORS错误Access to XMLHttpRequest at 'https://www.countrysideveterinaryclinic.org/sites/default/files/interesting-cat-facts.jpg' from origin 'http://localhost:1337' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Solution 从这里没有帮助
我的middleware.js
module.exports = [
'strapi::errors',
'strapi::security',
'strapi::poweredBy',
{
name: 'strapi::cors',
config: {
enabled: true,
header: '*',
origin: ['http://localhost:1337']
}
},
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
];
【问题讨论】:
-
您遇到了什么问题?如果您收到 CORS 错误消息,请将其添加到您的问题中。
-
请注意,the documentation for Strapi's CORS middleware 提到了
headers(复数)属性,但没有提到header(单数)属性。
标签: javascript cors localhost strapi