From 03bcc12260786138a4aeba9bb6a1eb9d065a1793 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Fri, 4 Jul 2025 00:44:48 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=AE=BE=E7=BD=AE=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/GuliMallCorsConfiguration.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/config/GuliMallCorsConfiguration.java diff --git a/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/config/GuliMallCorsConfiguration.java b/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/config/GuliMallCorsConfiguration.java new file mode 100644 index 0000000..41971ae --- /dev/null +++ b/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/config/GuliMallCorsConfiguration.java @@ -0,0 +1,24 @@ +package com.xunqi.gulimall.gateway.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; + +@Configuration +public class GuliMallCorsConfiguration { + + @Bean + public CorsWebFilter corsWebFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("*"); + corsConfiguration.setAllowCredentials(true); + + source.registerCorsConfiguration("/**", corsConfiguration); + return new CorsWebFilter(source); + } +}