I\'m using axios to make a axios.get call in my redux action.js file. In my component this action is performed on form submission.
I\'m getting status 200
The first confusion I had tackling this problem was understanding what a preflight request means. So I will start from there.
Browsers send preflight requests whenever a request does not meet these criteria:
Preflight requests are made with an OPTIONS method that includes three additional headers that your server may not be expecting if it is not configured for CORS. They are:
If the server isn't configured for CORS, it simply responds with an empty header having HTTP status code 200. Once you have configured the server for CORS, you should include the headers listed above as headers supported by CORS.
That should clear the error and allow you communicate with the server.
Note: While your server can handle the custom header you created (in my case, Authorization
for JWT authentication), it most likely won't be configured for CORS request. If you have access to your server, simply find out how to configure CORS for that server.
For more information about CORS. See https://www.html5rocks.com/en/tutorials/cors/
The problem is not with axios. The issue is with the server. When you serve up data you must add the following headers, before sending it.
Access-Control-Allow-Origin must be set to *
Access-Control-Allow-Headers must be set to Origin, X-Requested-With, Content-Type, Accept
This worked for me:
axios.create({
baseURL: "http://localhost:8088"
}).get('/myapp/user/list')
.then(function(response) {
callback && callback(response);
debugger;
})