From e6149ecb026288a53b4e44590efeff04be78a266 Mon Sep 17 00:00:00 2001 From: gewuyou Date: Fri, 9 May 2025 14:16:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(llmx-core-service):=20=E6=B7=BB=E5=8A=A0CO?= =?UTF-8?q?RS=E9=85=8D=E7=BD=AE=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增CorsConfig类,实现全局CORS配置 - 允许所有来源、所有HTTP方法和所有请求头- 禁用Cookie携带,预检请求缓存时间为3600秒 --- .../llmx/core/service/config/CorsConfig.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/CorsConfig.kt diff --git a/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/CorsConfig.kt b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/CorsConfig.kt new file mode 100644 index 0000000..e23a21a --- /dev/null +++ b/llmx-core/llmx-core-service/src/main/kotlin/org/jcnc/llmx/core/service/config/CorsConfig.kt @@ -0,0 +1,23 @@ +package org.jcnc.llmx.core.service.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.CorsRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer + +/** + *CORS配置 + * + * @since 2025-04-02 17:03:41 + * @author gewuyou + */ +@Configuration +open class CorsConfig : WebMvcConfigurer { + override fun addCorsMappings(registry: CorsRegistry) { + registry.addMapping("/**") // 匹配所有路径 + .allowedOrigins("*") // 允许所有来源(生产环境建议指定具体域名) + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的HTTP方法 + .allowedHeaders("*") // 允许所有请求头 + .allowCredentials(false) // 是否允许携带Cookie(true时需要明确指定allowedOrigins,不能为*) + .maxAge(3600) // 预检请求缓存时间(秒) + } +} \ No newline at end of file