a have a Spring boot(v5) with embeded tomcat
REST API for my small Angular 5
website,
and this REST API is on https
protocol, so I need to enable cors origin
to let my website communicate with REST API.
How do I did that:
@SpringBootApplication
public class AdminPanelApplication {
public static void main(String[] args) {
SpringApplication.run(AdminPanelApplication.class, args);
}
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowCredentials(true)
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*");
}
};
}
}
But with this cors origin
, my website started to sent 2 requests for all requests, first is OPTION request, second is real one(get,post etc).
I assume this is bad, at least for load to the server(instead of sending one request, I'm always send two(even tho first is very light weight option
request), I don't see this behavior on any website(for example stackoverflow :) )
Example:
So I assume I'm doing something wrong, so how to set up cors origin(or something else maybe), in right way?