CORS Issue with Spring Boot Api


I currently have a JAVA Spring Boot Api deployed on render. When running the server locally, I am able to call the api from both my React frontend and Postman. However, when I call the same api after it has been hosted on render, I get this error:

localhost/:1 Access to XMLHttpRequest at '' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

When the api is run locally, responses returned from the api contain the “Access-Control-Allow-Origin: *” header. However, after the api is hosted on Render, the response header “Access-Control-Allow-Origin: *” is removed for some reason.

Lastly, it is worth mentioning that I can interact with the api when it is hosted on Render perfectly well using POSTMAN, however, not through my react app.

Any help is appreciated.

Hi there,

If you are sure your service is configured correctly to add the correct CORS headers to your responses, usually errors like this occur when the response to the call to your API is erroring and returning a 502 response. The 502 response is coming from our proxy layer and not from your service, so it will be missing the CORS headers.

Please look into why your API is responding with a 502. Check if the service is not becoming unhealthy or is crashing. I would test that your API is responding correctly when you call it directly through curl or some other tool, like Postman.


Render Support, UTC+10 :australia:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.