Created
October 23, 2023 23:05
-
-
Save fcaldarelli/65f7359d63a6a1344a0ba77ad86c8ab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.stream.Collectors; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.http.HttpMethod; | |
import org.springframework.web.cors.CorsConfiguration; | |
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | |
import org.springframework.web.filter.CorsFilter; | |
/** | |
* | |
* @author vaquar | |
* | |
*/ | |
@SpringBootApplication | |
public class SpringbootApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(SpringbootApplication.class, args); | |
} | |
@Bean | |
public CorsFilter corsFilter() { | |
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | |
final CorsConfiguration config = new CorsConfiguration(); | |
config.setAllowCredentials(true); | |
config.setAllowedOrigins(Collections.singletonList("*")); | |
config.setAllowedHeaders(Collections.singletonList("*")); | |
config.setAllowedMethods(Arrays.stream(HttpMethod.values()).map(HttpMethod::name).collect(Collectors.toList())); | |
source.registerCorsConfiguration("/**", config); | |
return new CorsFilter(source); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment