ontology-driven-api icon indicating copy to clipboard operation
ontology-driven-api copied to clipboard

cors allow origin * headers is not set

Open JJ-Author opened this issue 5 years ago • 2 comments

set Access-Control-Allow-Origin: * header for api calls

JJ-Author avatar Mar 05 '19 17:03 JJ-Author

Hi, I managed to set CORS by adding the following code to src/main/java/dbpedia/api/Start.java:

import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

And right below the main() function:

@Bean
public WebMvcConfigurer corsConfigurer() {
     return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedOrigins(
                "http://localhost:3000"
            );
        }
     };
  }

francoguilherme avatar Jun 23 '19 21:06 francoguilherme

Hi @francoguilherme could you create a PR then also the credits go to you and it is more transparent.

JJ-Author avatar Jun 28 '19 07:06 JJ-Author