From ae1c7b06f7cb5e7e1753698f32d7f8c4ab38c4b4 Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Tue, 1 Jul 2025 02:57:33 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=85=81=E8=AE=B8=E8=B7=A8=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cloverta/webapi/config/CorsConfig.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/com/cloverta/webapi/config/CorsConfig.java diff --git a/src/main/java/com/cloverta/webapi/config/CorsConfig.java b/src/main/java/com/cloverta/webapi/config/CorsConfig.java new file mode 100644 index 0000000..48dd531 --- /dev/null +++ b/src/main/java/com/cloverta/webapi/config/CorsConfig.java @@ -0,0 +1,17 @@ +package com.cloverta.webapi.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 CorsConfig implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") // 应用于所有端点 + .allowedOrigins("*") // 允许所有来源 + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法 + .allowedHeaders("*") // 允许所有头部 + .maxAge(3600); // 预检请求缓存时间(秒) + } +} \ No newline at end of file