Spring Boot Docker Application CORS Error

58 Views Asked by At

I am running a docker app on Render.com and its getting cors error. My server, my dataabase and my docker apps are on render and deployed. I can access to the server running on the render from localhost, and get response data. But I can not send request to the server from the render url origin. I have set up the cors in server and it looks like this.

@Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("https://spring-react-crud-app-1.onrender.com", "http://localhost:5173")
                        .allowedMethods("GET", "POST", "PUT", "DELETE")
                        .allowedHeaders(HttpHeaders.CONTENT_TYPE);
            }
        };
    }

While server is running on local host, I can access it from both local host render origins.

I have tried adding @CrossOrigin to my controller and still not working.

0

There are 0 best solutions below