Request blocked by CORS policy

Hi everyone. I am facing problem regarding CORS issue. I have an spring boot api which is hosted on github. I have deployed it on render by Docker. I have configured CORS and this is my config file

@Configuration
public class CorsConfig {
    @Bean
    public WebMvcConfigurer corsConfigurer() {

        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins("*")
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                        .allowedHeaders("*");
            }
        };
    }
}

When I am testting the api via postman its running fine. After deplying on render.com I am making the post request from frontend like this

try {
        const data = prepareData();
        const { data : response } = await axios.post(`https://numerical-methods-solver.onrender.com/api/v1/interpolation/newtonForwardInterpolation`,
          data
        );
        setResult(response);
      } catch (error) {
        console.error("Error in Axios request:", error);
      }

Its giving CORS error

I have gone through all the topics on this community regarding this but still not resolved. Please help

This issue is resolved. I haven’t updated the jar file

1 Like

Hello.
could you please help me. I don’t understand why my POST request doesn’t work. I make the post request from frontend as a formData. What kind of endpoint should be? I see you make https://numerical-methods-solver.onrender.com/api/v1. But if i have an index.php in the root of my app, how can i receive back the response to frontend. The post request with the endpoint like **/v1/index.php or **/api/v1/index.php doesn’t work.
This is my question here: POST request is wrong
Thank you!

You have to make api call to specific endpoint of the api to get the data to frontend. After that you can show the data to frontend as you like. Here are the endpoints for this api https://numerical-methods-solver.onrender.com/

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