I tried everything, adding all the headers and changing the options too but it seems that whatever I do, the cors error still haunts me.
I get his error: CORS Missing Allow Origin
The frontend of my website is hosted on netlify and the backend on heroku. I am using react, axios, mysql, node and express. I also haven't fully set up the domain name but the website works fine except for the cors error that happens only on certain post requests. Suprisingly I think I got the preflight request working but it is also uncertain at times.
here is my express node setup:
var cors = require('cors');
app.use(cors({ origin: true, credentials: true }));
app.options('*', cors())
app.use(express.static("./public"));
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
Here is how my axios requests look like:
Axios.post("https://backendurl" , {
headers : {
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept, Authorization",
'Content-Type': "application/json; charset=utf-8",
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': "GET, POST, PUT, DELETE OPTIONS",
'Accept': '*',
// Accept: '*',
},
params: {
name: name,
}
}).then((response) => {
console.log(response.data);
});
I also tried setting up a proxy through the allow all cors request server but it didn't work either.
If anyone has any leads that would be of interest to solve this cors issue that would be great. Especially concerning the main post request. Thanks a lot.