Commit 5a9268845cb192d0067ece8e4cf26038588dcbd9
1 parent
a54afccc
Exists in
master
网关中添加处理上下游服务重复添加跨域问题
Showing
6 changed files
with
86 additions
and
9 deletions
Show diff stats
cloud/autho/pom.xml
@@ -69,7 +69,7 @@ | @@ -69,7 +69,7 @@ | ||
69 | 69 | ||
70 | <build> | 70 | <build> |
71 | <!--打包文件名--> | 71 | <!--打包文件名--> |
72 | - <finalName>quartz_server</finalName> | 72 | + <finalName>auth</finalName> |
73 | <!--打包方式--> | 73 | <!--打包方式--> |
74 | <plugins> | 74 | <plugins> |
75 | <!-- 设置编译版本 --> | 75 | <!-- 设置编译版本 --> |
@@ -91,7 +91,7 @@ | @@ -91,7 +91,7 @@ | ||
91 | <configuration> | 91 | <configuration> |
92 | <archive> | 92 | <archive> |
93 | <manifest> | 93 | <manifest> |
94 | - <mainClass>com.sincere.userSearch.UserApplication</mainClass> | 94 | + <mainClass>com.sincere.autho.AuthoApplication</mainClass> |
95 | <addClasspath>true</addClasspath> | 95 | <addClasspath>true</addClasspath> |
96 | <classpathPrefix>lib/</classpathPrefix> | 96 | <classpathPrefix>lib/</classpathPrefix> |
97 | </manifest> | 97 | </manifest> |
cloud/autho/src/main/resources/application.yaml
@@ -24,5 +24,5 @@ eureka: | @@ -24,5 +24,5 @@ eureka: | ||
24 | lease-renewal-interval-in-seconds: 10 | 24 | lease-renewal-interval-in-seconds: 10 |
25 | client: | 25 | client: |
26 | service-url: | 26 | service-url: |
27 | - defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ | 27 | + defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ |
28 | 28 |
cloud/getaway/src/main/java/com/sincere/getaway/client/config/CorsConfig.java
0 → 100644
@@ -0,0 +1,75 @@ | @@ -0,0 +1,75 @@ | ||
1 | +//package com.sincere.getaway.client.config; | ||
2 | +// | ||
3 | +//import org.springframework.cloud.client.discovery.DiscoveryClient; | ||
4 | +//import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator; | ||
5 | +//import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties; | ||
6 | +//import org.springframework.cloud.gateway.route.RouteDefinitionLocator; | ||
7 | +//import org.springframework.context.annotation.Bean; | ||
8 | +//import org.springframework.context.annotation.Configuration; | ||
9 | +//import org.springframework.http.HttpHeaders; | ||
10 | +//import org.springframework.http.HttpMethod; | ||
11 | +//import org.springframework.http.HttpStatus; | ||
12 | +//import org.springframework.http.codec.ServerCodecConfigurer; | ||
13 | +//import org.springframework.http.codec.support.DefaultServerCodecConfigurer; | ||
14 | +//import org.springframework.http.server.reactive.ServerHttpRequest; | ||
15 | +//import org.springframework.http.server.reactive.ServerHttpResponse; | ||
16 | +//import org.springframework.web.cors.reactive.CorsUtils; | ||
17 | +//import org.springframework.web.server.ServerWebExchange; | ||
18 | +//import org.springframework.web.server.WebFilter; | ||
19 | +//import org.springframework.web.server.WebFilterChain; | ||
20 | +//import reactor.core.publisher.Mono; | ||
21 | +// | ||
22 | +///** | ||
23 | +// * * 程序名 : CorsConfig | ||
24 | +// * 建立日期: 2018-09-09 | ||
25 | +// * 作者 : someday | ||
26 | +// * 模块 : 网关 | ||
27 | +// * 描述 : 跨域 | ||
28 | +// * 备注 : version20180909001 | ||
29 | +// * <p> | ||
30 | +// * 修改历史 | ||
31 | +// * 序号 日期 修改人 修改原因 | ||
32 | +// */ | ||
33 | +//@Configuration | ||
34 | +//public class CorsConfig { | ||
35 | +// private static final String ALL = "*"; | ||
36 | +// private static final String MAX_AGE = "18000L"; | ||
37 | +// | ||
38 | +// @Bean | ||
39 | +// public RouteDefinitionLocator discoveryClientRouteDefinitionLocator(DiscoveryClient discoveryClient, | ||
40 | +// DiscoveryLocatorProperties properties) { | ||
41 | +// return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties); | ||
42 | +// } | ||
43 | +// | ||
44 | +// @Bean | ||
45 | +// public ServerCodecConfigurer serverCodecConfigurer() { | ||
46 | +// return new DefaultServerCodecConfigurer(); | ||
47 | +// } | ||
48 | +// | ||
49 | +// @Bean | ||
50 | +// public WebFilter corsFilter() { | ||
51 | +// return (ServerWebExchange ctx, WebFilterChain chain) -> { | ||
52 | +// ServerHttpRequest request = ctx.getRequest(); | ||
53 | +// if (!CorsUtils.isCorsRequest(request)) { | ||
54 | +// return chain.filter(ctx); | ||
55 | +// } | ||
56 | +// HttpHeaders requestHeaders = request.getHeaders(); | ||
57 | +// ServerHttpResponse response = ctx.getResponse(); | ||
58 | +// HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod(); | ||
59 | +// HttpHeaders headers = response.getHeaders(); | ||
60 | +// headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, requestHeaders.getOrigin()); | ||
61 | +// headers.addAll(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, requestHeaders.getAccessControlRequestHeaders()); | ||
62 | +// if (requestMethod != null) { | ||
63 | +// headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, requestMethod.name()); | ||
64 | +// } | ||
65 | +// headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); | ||
66 | +// headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, ALL); | ||
67 | +// headers.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE); | ||
68 | +// if (request.getMethod() == HttpMethod.OPTIONS) { | ||
69 | +// response.setStatusCode(HttpStatus.OK); | ||
70 | +// return Mono.empty(); | ||
71 | +// } | ||
72 | +// return chain.filter(ctx); | ||
73 | +// }; | ||
74 | +// } | ||
75 | +//} |
cloud/getaway/src/main/resources/application.yml
@@ -22,7 +22,7 @@ spring: | @@ -22,7 +22,7 @@ spring: | ||
22 | allowedHeaders: "*" | 22 | allowedHeaders: "*" |
23 | routes: | 23 | routes: |
24 | - id: usersearch | 24 | - id: usersearch |
25 | - uri: lb://usersearch | 25 | + uri: http://121.40.30.78:9004 |
26 | predicates: | 26 | predicates: |
27 | - Path=/usersearch/** | 27 | - Path=/usersearch/** |
28 | filters: | 28 | filters: |
@@ -42,11 +42,13 @@ spring: | @@ -42,11 +42,13 @@ spring: | ||
42 | filters: | 42 | filters: |
43 | - StripPrefix=1 | 43 | - StripPrefix=1 |
44 | - id: authserver | 44 | - id: authserver |
45 | - uri: lb://authserver | 45 | + uri: http://121.40.30.78:9005 |
46 | predicates: | 46 | predicates: |
47 | - Path=/authserver/** | 47 | - Path=/authserver/** |
48 | filters: | 48 | filters: |
49 | - StripPrefix=1 | 49 | - StripPrefix=1 |
50 | + default-filters: | ||
51 | + - DedupeResponseHeader=Access-Control-Allow-Origin, RETAIN_UNIQUE | ||
50 | # discovery: | 52 | # discovery: |
51 | # locator: | 53 | # locator: |
52 | # lowerCaseServiceId: true | 54 | # lowerCaseServiceId: true |
@@ -68,4 +70,4 @@ ribbon: | @@ -68,4 +70,4 @@ ribbon: | ||
68 | 70 | ||
69 | 71 | ||
70 | url: | 72 | url: |
71 | - ignored: /SmartCampusWebApi/**,/authserver/** | ||
72 | \ No newline at end of file | 73 | \ No newline at end of file |
74 | + ignored: /SmartCampusWebApi/**,/authserver/** | ||
73 | \ No newline at end of file | 75 | \ No newline at end of file |
cloud/pom.xml
@@ -113,7 +113,7 @@ | @@ -113,7 +113,7 @@ | ||
113 | </dependency> | 113 | </dependency> |
114 | </dependencies> | 114 | </dependencies> |
115 | </dependencyManagement> | 115 | </dependencyManagement> |
116 | - <build> | 116 | + <!--<build> |
117 | <pluginManagement> | 117 | <pluginManagement> |
118 | <plugins> | 118 | <plugins> |
119 | <plugin> | 119 | <plugin> |
@@ -185,7 +185,7 @@ | @@ -185,7 +185,7 @@ | ||
185 | <filtering>false</filtering> | 185 | <filtering>false</filtering> |
186 | </resource> | 186 | </resource> |
187 | </resources> | 187 | </resources> |
188 | - </build> | 188 | + </build>--> |
189 | 189 | ||
190 | <!-- 形成带第三方jar包的可执行jar包,jar包目录结构如下 application.properties lib META-INF mybatis | 190 | <!-- 形成带第三方jar包的可执行jar包,jar包目录结构如下 application.properties lib META-INF mybatis |
191 | org --> | 191 | org --> |
cloud/user_search/src/main/resources/application.yaml
@@ -24,5 +24,5 @@ eureka: | @@ -24,5 +24,5 @@ eureka: | ||
24 | lease-renewal-interval-in-seconds: 10 | 24 | lease-renewal-interval-in-seconds: 10 |
25 | client: | 25 | client: |
26 | service-url: | 26 | service-url: |
27 | - defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ | 27 | + defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ |
28 | 28 |