When I run this command:
curl -X POST -H 'Content-type: applicatiojson' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/XXXXXXXXX/XXX/XXXX
Everything posts the way I want. But, in javascript, when I run the post request:
fetch('https://hooks.slack.com/services/XXXXXXXXX/XXX/XXXX', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*"
},
text: "Hello, world."
})
I keep getting the error:
Access to fetch at 'https://hooks.slack.com/services/XXXX/XXXX/XXXX' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I thought this was the problem: Deadly CORS when http://localhost is the origin But then I tried opening my own ngrok and got the same error. I also tried installing the Allow-Control-Allow-Origin chrome extension to no avail. Also, as you can see in my code, I set it to allow access for CORS. Lastly, I tried on firefox but still wouldn't work. Does anyone know what the problem could be?