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 | 69 | |
70 | 70 | <build> |
71 | 71 | <!--打包文件名--> |
72 | - <finalName>quartz_server</finalName> | |
72 | + <finalName>auth</finalName> | |
73 | 73 | <!--打包方式--> |
74 | 74 | <plugins> |
75 | 75 | <!-- 设置编译版本 --> |
... | ... | @@ -91,7 +91,7 @@ |
91 | 91 | <configuration> |
92 | 92 | <archive> |
93 | 93 | <manifest> |
94 | - <mainClass>com.sincere.userSearch.UserApplication</mainClass> | |
94 | + <mainClass>com.sincere.autho.AuthoApplication</mainClass> | |
95 | 95 | <addClasspath>true</addClasspath> |
96 | 96 | <classpathPrefix>lib/</classpathPrefix> |
97 | 97 | </manifest> | ... | ... |
cloud/autho/src/main/resources/application.yaml
cloud/getaway/src/main/java/com/sincere/getaway/client/config/CorsConfig.java
0 → 100644
... | ... | @@ -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 | 22 | allowedHeaders: "*" |
23 | 23 | routes: |
24 | 24 | - id: usersearch |
25 | - uri: lb://usersearch | |
25 | + uri: http://121.40.30.78:9004 | |
26 | 26 | predicates: |
27 | 27 | - Path=/usersearch/** |
28 | 28 | filters: |
... | ... | @@ -42,11 +42,13 @@ spring: |
42 | 42 | filters: |
43 | 43 | - StripPrefix=1 |
44 | 44 | - id: authserver |
45 | - uri: lb://authserver | |
45 | + uri: http://121.40.30.78:9005 | |
46 | 46 | predicates: |
47 | 47 | - Path=/authserver/** |
48 | 48 | filters: |
49 | 49 | - StripPrefix=1 |
50 | + default-filters: | |
51 | + - DedupeResponseHeader=Access-Control-Allow-Origin, RETAIN_UNIQUE | |
50 | 52 | # discovery: |
51 | 53 | # locator: |
52 | 54 | # lowerCaseServiceId: true |
... | ... | @@ -68,4 +70,4 @@ ribbon: |
68 | 70 | |
69 | 71 | |
70 | 72 | url: |
71 | - ignored: /SmartCampusWebApi/**,/authserver/** | |
72 | 73 | \ No newline at end of file |
74 | + ignored: /SmartCampusWebApi/**,/authserver/** | |
73 | 75 | \ No newline at end of file | ... | ... |
cloud/pom.xml
... | ... | @@ -113,7 +113,7 @@ |
113 | 113 | </dependency> |
114 | 114 | </dependencies> |
115 | 115 | </dependencyManagement> |
116 | - <build> | |
116 | + <!--<build> | |
117 | 117 | <pluginManagement> |
118 | 118 | <plugins> |
119 | 119 | <plugin> |
... | ... | @@ -185,7 +185,7 @@ |
185 | 185 | <filtering>false</filtering> |
186 | 186 | </resource> |
187 | 187 | </resources> |
188 | - </build> | |
188 | + </build>--> | |
189 | 189 | |
190 | 190 | <!-- 形成带第三方jar包的可执行jar包,jar包目录结构如下 application.properties lib META-INF mybatis |
191 | 191 | org --> | ... | ... |
cloud/user_search/src/main/resources/application.yaml