MCPcopy Create free account
hub / github.com/PlexPt/rocket-pt / CorsConfig

Class CorsConfig

src/main/java/com/rocketpt/server/config/CorsConfig.java:18–39  ·  view source on GitHub ↗

CORS跨域 @author pt

Source from the content-addressed store, hash-verified

16 * @author pt
17 */
18@Slf4j
19@Configuration
20public class CorsConfig {
21
22
23 @Bean
24 public CorsFilter corsFilter() {
25 CorsConfiguration corsConfiguration = new CorsConfiguration();
26 //1,允许任何来源
27 corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
28 //2,允许任何请求头
29 corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
30 //3,允许任何方法
31 corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
32 //4,允许凭证
33 corsConfiguration.setAllowCredentials(true);
34
35 UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
36 source.registerCorsConfiguration("/**", corsConfiguration);
37 return new CorsFilter(source);
38 }
39}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected