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