Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-oss
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-oss
Commits
9fa6ce16
Commit
9fa6ce16
authored
Feb 02, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/test' into prod
parents
96e71469
e1439a31
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
yd-oss-api/src/main/java/com/yd/oss/api/config/CorsConfig.java
+47
-0
No files found.
yd-oss-api/src/main/java/com/yd/oss/api/config/CorsConfig.java
0 → 100644
View file @
9fa6ce16
package
com
.
yd
.
oss
.
api
.
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
;
@Configuration
public
class
CorsConfig
{
@Bean
public
CorsFilter
corsFilter
()
{
CorsConfiguration
config
=
new
CorsConfiguration
();
// 允许的源,这里设为 * 表示允许所有,生产环境建议指定具体域名
config
.
addAllowedOrigin
(
"*"
);
// 允许的请求方法
config
.
addAllowedMethod
(
"GET"
);
config
.
addAllowedMethod
(
"POST"
);
config
.
addAllowedMethod
(
"PUT"
);
config
.
addAllowedMethod
(
"DELETE"
);
config
.
addAllowedMethod
(
"OPTIONS"
);
config
.
addAllowedMethod
(
"PATCH"
);
// 允许的请求头
config
.
addAllowedHeader
(
"*"
);
// 是否允许携带凭证(cookies等)
config
.
setAllowCredentials
(
false
);
// 预检请求的缓存时间(秒)
config
.
setMaxAge
(
3600L
);
// 暴露的响应头
config
.
addExposedHeader
(
"Content-Disposition"
);
config
.
addExposedHeader
(
"Authorization"
);
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
// 对所有路径生效
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment