sunmingtao / sample-code

3 stars 4 forks source link

Newspaper UI can't see login button locally: CORS header ‘Access-Control-Allow-Origin’ missing #214

Closed sunmingtao closed 3 years ago

sunmingtao commented 3 years ago

It's because the button at top right corner is loaded using ajax, and localhost:8081 is considered a different domain from localhost:8082.

The solution is enable cross domain, but only for 'local' profile.

Add a 'local' bean

@Bean
@Profile("local")
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedOrigins("*").allowCredentials(true);
        }
    };
}