feat(config): add CORS configuration for development environment

- configure global CORS policy allowing all origins, headers, and methods
- register CorsFilter bean for cross-origin request handling
- bump version to v0.1f
This commit is contained in:
2026-05-24 20:37:41 +08:00
parent 87e31efa85
commit 9521edaa43
2 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
}
group = "com.msksbr"
version = "v0.1"
version = "v0.1f"
description = "bookMgr"
java {
@@ -0,0 +1,31 @@
package com.msksbr.bookmgr.config
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter
/*
* CORS 跨域配置
* 配置全局 CORS 策略,允许所有来源(origins)、请求头(headers)和 HTTP 方法
* 适用于前后端分离架构下的开发环境;生产环境建议按需收紧 allowedOrigins
*/
@Configuration
class CorsConfig {
/*
* 注册 CorsFilter Bean
* 拦截所有 / 路径并应用允许跨域的配置
*/
@Bean
fun corsFilter(): CorsFilter {
val config = CorsConfiguration()
config.addAllowedOrigin("*")
config.addAllowedHeader("*")
config.addAllowedMethod("*")
val source = UrlBasedCorsConfigurationSource()
source.registerCorsConfiguration("/**", config)
return CorsFilter(source)
}
}