I have such a generic method to send post requests
async function postData(uri = '', data = {}) {
let url = process.env.VUE_APP_API_URL + uri;
const response = await fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'omit',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
return await handleErrors(response)
}
function handleErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
as you can see I set Access-Control-Allow-Origin
to *
, which means all URLs allowed, right? but for some reason I still see cors issue when sending POST requests, but Access-Control-Allow-Origin
header exists in the request headers https://gyazo.com/f59fb77cc812f76952f7fbc243356415.