From 5a3df648a267958e1806192ab02473d5528cfb1f Mon Sep 17 00:00:00 2001 From: Wonder Date: Wed, 8 Oct 2025 00:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=94=84Update:=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BA=86=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/hezhaohui/mail/config/WebConfig.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 backend/src/main/java/cn/hezhaohui/mail/config/WebConfig.java diff --git a/backend/src/main/java/cn/hezhaohui/mail/config/WebConfig.java b/backend/src/main/java/cn/hezhaohui/mail/config/WebConfig.java new file mode 100644 index 0000000..4393d26 --- /dev/null +++ b/backend/src/main/java/cn/hezhaohui/mail/config/WebConfig.java @@ -0,0 +1,19 @@ +package cn.hezhaohui.mail.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") // 应用到所有路径 + .allowedOrigins("http://localhost:5173") // 允许前端开发服务器的源 + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的HTTP方法 + .allowedHeaders("*") // 允许所有header + .allowCredentials(true) // 允许发送凭证信息(如cookies) + .maxAge(3600); // 预检请求的有效期,单位为秒 + } +}