Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
15a2087a
Commit
15a2087a
authored
Apr 29, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决网关跨域
parent
250d9109
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
GatewayApplication.java
...ay/src/main/java/com/byit/gateway/GatewayApplication.java
+21
-0
No files found.
byit-myth-gateway/src/main/java/com/byit/gateway/GatewayApplication.java
View file @
15a2087a
...
...
@@ -5,6 +5,10 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
/**
* @author Liyuan
...
...
@@ -24,4 +28,21 @@ public class GatewayApplication {
SpringApplication
.
run
(
GatewayApplication
.
class
,
args
);
log
.
info
(
"网关启动成功……"
);
}
private
CorsConfiguration
corsConfiguration
(){
CorsConfiguration
corsConfiguration
=
new
CorsConfiguration
();
corsConfiguration
.
addAllowedOrigin
(
"*"
);
corsConfiguration
.
addAllowedHeader
(
"*"
);
corsConfiguration
.
addAllowedMethod
(
"*"
);
corsConfiguration
.
setAllowCredentials
(
true
);
corsConfiguration
.
setMaxAge
(
3600L
);
return
corsConfiguration
;
}
@Bean
public
CorsFilter
corsFilter
(){
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
corsConfiguration
());
return
new
CorsFilter
(
source
);
}
}
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