I have a local Ballerina server (http://localhost:8080) and React frontend (http://localhost:3000) set up, and I’ve encountered a CORS error while attempting to send POST requests to the server through axios. Interestingly, I don’t encounter this error when making the same requests through Postman.
Following is the CORS error:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
How can I solve this problem ?
2
Answers
Postman doesn't validate the CORS headers. However, browsers do validate them as a security measure to protect against cross-site requests. To resolve this CORS error, add 'http://localhost:3000' to the CORS configuration of the service. Here's an example of how to configure it:
This configuration will allow requests from the React app running on 'http://localhost:3000' to access the Ballerina server without encountering CORS issues.
if u use google chrome: