CORS and Camunda Spring Boot REST API 7.15

I am trying to call Camunda Spring Boot APIs using Angular Web Application, I have configured CORS property in YAML file as the following:
camunda.bpm.run.cors:
enabled: true
allowed-origins: “http://localhost:4200

Still getting below error
Access to XMLHttpRequest at ‘http://localhost:8089/’ from origin ‘http://localhost:4200’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Hi @omarmohaidat
What browser do you use? Do you have the same behaviour in Chrome and Firefox?

I am using google chrome, I got the same issue using firefox

the issue has been fixed after adding below code

Note: this code should be added in @Configuration class


@Bean
	public FilterRegistrationBean<CorsFilter> processCorsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("http://localhost:4200");
        config.addAllowedHeader("*");
        config.addAllowedMethod("*");
        source.registerCorsConfiguration("/**", config);

        FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(source));
        bean.setOrder(0);
        return bean;
    }
3 Likes