After going through various questions on CORS errors to no avail, I am facing a dilemma in my NuxtJS client application. Whenever I try to make a simple POST request using axios, I encounter CORS issues. However, when I switch to using the fetch API, everything works smoothly. Although the server has the correct "Access-Control-Allow-Origin" headers set, neither option below functions when that header is removed. Can anyone shed light on why fetch works fine but axios doesn't?
FAILS
await this.$axios({
url,
method: 'POST',
data
})
WORKS
await fetch(url, {
method: 'POST',
body: JSON.stringify(data)
})
Error message: Access to XMLHttpRequest at {URL} from origin 'http://localhost:3000' 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.
In the network tab of Chrome, the request headers show as follows: