System Information
- Strapi Version: 3.6.3
- Operating System:
- Database:
- Node Version:
- NPM Version:
- Yarn Version:
Hi!
When I’m using a loop to send many post requests in production, then some of them will give this error:
Access to XMLHttpRequest at 'https://api.domain.com/items' from origin 'https://app.domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Others will be successful. I have CORS origin in strapi config and I can send post requests, but when using a loop then sometimes it fails.
for(let i = 0; i < file.length; i++){
const data = {
name: file[i]["Name"],
number: file[i]["Number"],
category: category[0].value,
creator: auth.user.id
}
let productPhotoFromFile = Array.from(productPhotos).filter(obj => {
return obj.name === file[i]["Photo"];
});
const formData = new FormData();
if (productPhotoFromFile.length > 0) {
formData.append("files.photo", productPhotoFromFile[0].originFileObj);
} else {
const blob = await (await fetch(unknownPhoto)).blob();
formData.append("files.photo", blob);
}
formData.append("data", JSON.stringify(data));
try {
await axios.post(process.env.REACT_APP_API_URL + '/items', formData, {withCredentials: true});
} catch (error) {
console.log(error);
}
}
I can’t see anything in Strapi console and on localhost I don’t have this problem. Can’t understand what is causing this?