feat(llmx-core-service): 添加CORS配置类 #19

Merged
gewuyou merged 1 commits from dev into test 2025-05-09 14:17:28 +08:00

View File

@ -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) // 是否允许携带Cookietrue时需要明确指定allowedOrigins不能为*
.maxAge(3600) // 预检请求缓存时间(秒)
}
}