i have a ReactJS Client that tries to send a POST Request to my Camunda Engine. Whenever i submit my form i get following error:
Failed to load http://localhost:8080/rest/process-definition/key/TestBuildPipeline/submit-form: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:3000’ is therefore not allowed access. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
I tried with this solution, adding this Method to my Application Class
Then i got GET Requests to my Spring Boot Application to work. Still Camunda REST Engine is not working. After lot of research i didnt found any solution. Btw Postman does work.
I tried with the web.xml (like here) but i dont know where to put it… Right now i created the folder “src/main/webapp/WEB-INF” and put it there, but it doesnt seem to get processed. The other solution with the nginx proxy is way too much for my needs.
My Camunda Engine is running as a Spring Boot Application, i start it using Maven and i think Tomcat is deploying the server.
None of the above seemed to work for me, but finally got it working with:
@Bean
public FilterRegistrationBean processCorsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
Note that the Spring docs say to use method name corsFilter, but this results in an error: Bean named 'corsFilter' is expected to be of type 'org.springframework.web.filter.CorsFilter'.
Renaming the method to processCorsFilter did the trick.