I created a SendGrid form using CF Workers and set (for testing) Access-Control-Allow-Origin", '*' but it's being ignored on the frontend:
Access to XMLHttpRequest at 'https://<domain>.workers.dev/' from origin 'https://<frontend-domain>.dev' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Do I need to also add it to the AXIOS POST request?
Here's code from my workers file:
const myHeaders = new Headers();
myHeaders.set("Access-Control-Allow-Origin", '*');
myHeaders.set("Access-Control-Allow-Methods", "GET,HEAD,POST,OPTIONS");
myHeaders.set("Access-Control-Max-Age", "86400",);
return new Response((emailResponse.ok), {status: 200, headers: myHeaders})
And here's the AXIOS request:
this.$axios.$post(
"https://<domain>.workers.dev/",
{
name: this.mailData.name,
eMail: this.mailData.eMail,
phone: this.mailData.phone,
message: this.mailData.message,
},
{
headers: {
"Content-Type": "application/json",
},
}
);
It all works fine using Insomnia and the headers are visible there:
