refactor(llmx-core):调整跨域配置并优化部分代码
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 4m13s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 4m13s
- 移除全局 CorsConfig 类,注释保留备用- 在 ChatController 中添加跨域配置 - 将 AppConfiguration 类和 webClientBuilder 方法改为开放
This commit is contained in:
parent
e6149ecb02
commit
7400c4d24f
@ -14,7 +14,7 @@ import org.springframework.web.reactive.function.client.WebClient
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ModelProperties::class)
|
||||
class AppConfiguration {
|
||||
open class AppConfiguration {
|
||||
/**
|
||||
* 创建一个配置了负载均衡的WebClient构建器
|
||||
*
|
||||
@ -25,7 +25,7 @@ class AppConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
fun webClientBuilder(): WebClient.Builder {
|
||||
open fun webClientBuilder(): WebClient.Builder {
|
||||
return WebClient.builder()
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,36 @@
|
||||
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) // 预检请求缓存时间(秒)
|
||||
}
|
||||
}
|
||||
//package org.jcnc.llmx.core.service.config
|
||||
//
|
||||
//import com.gewuyou.forgeboot.core.extension.log
|
||||
//import org.springframework.context.annotation.Configuration
|
||||
//import org.springframework.web.servlet.config.annotation.CorsRegistry
|
||||
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
//
|
||||
///**
|
||||
// * CORS配置类
|
||||
// *
|
||||
// * 该类用于全局配置跨域请求设置,以确保前端应用可以与后端服务进行通信
|
||||
// * 主要通过重写addCorsMappings方法来配置跨域请求映射,以及通过corsWebFilter方法来提供更细粒度的跨域支持
|
||||
// *
|
||||
// * @since 2025-04-02 17:03:41
|
||||
// * @author gewuyou
|
||||
// */
|
||||
//@Configuration
|
||||
//open class CorsConfig : WebMvcConfigurer {
|
||||
// /**
|
||||
// * 添加跨域请求映射
|
||||
// *
|
||||
// * 该方法重写了父接口中的addCorsMappings方法,用于配置全局的跨域请求规则
|
||||
// * 主要配置了允许所有路径、所有来源、常见HTTP方法、所有请求头的跨域请求,并设置了不携带Cookie以及预检请求缓存时间
|
||||
// *
|
||||
// * @param registry 跨域请求注册表,用于添加跨域请求映射
|
||||
// */
|
||||
// override fun addCorsMappings(registry: CorsRegistry) {
|
||||
// log.info("Web CORS配置生效")
|
||||
// registry.addMapping("/**") // 匹配所有路径
|
||||
// .allowedOrigins("*") // 允许所有来源(生产环境建议指定具体域名)
|
||||
// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的HTTP方法
|
||||
// .allowedHeaders("*") // 允许所有请求头
|
||||
// .allowCredentials(false) // 是否允许携带Cookie(true时需要明确指定allowedOrigins,不能为*)
|
||||
// .maxAge(3600) // 预检请求缓存时间(秒)
|
||||
// }
|
||||
//}
|
||||
|
||||
@ -8,6 +8,7 @@ import org.jcnc.llmx.core.service.service.impl.LLMServiceImpl
|
||||
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.web.bind.annotation.CrossOrigin
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@ApiVersion
|
||||
@RestController
|
||||
@RequestMapping("/chat")
|
||||
@CrossOrigin(origins = ["*"]) // 放宽跨域
|
||||
class ChatController(
|
||||
private val llmServiceImpl: LLMServiceImpl
|
||||
) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user