From 140270c52a78a7cc6dde7dc5de80bbec69057930 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Fri, 12 Nov 2021 23:35:17 +0800 Subject: [PATCH] =?UTF-8?q?Feature:=20=E9=80=82=E9=85=8D=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=20Axios=20CORS=20=E8=B7=A8=E5=9F=9F=E9=94=99=E8=AF=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threadpool/starter/config/CorsConfig.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 hippo4j-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/CorsConfig.java diff --git a/hippo4j-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/CorsConfig.java b/hippo4j-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/CorsConfig.java new file mode 100644 index 00000000..0dfdab85 --- /dev/null +++ b/hippo4j-spring-boot-starter/src/main/java/com/github/dynamic/threadpool/starter/config/CorsConfig.java @@ -0,0 +1,31 @@ +package com.github.dynamic.threadpool.starter.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * Cors config. + * + * @author chen.ma + * @date 2021/11/12 21:46 + */ +public class CorsConfig { + + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("GET"); + return corsConfiguration; + } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + +}