Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
喜欢杯子
microservices-platform
提交
548a5bb2
microservices-platform
项目概览
喜欢杯子
/
microservices-platform
与 Fork 源项目一致
Fork自
whatyn / microservices-platform
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
548a5bb2
编写于
4月 03, 2019
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
暂时删除spring-cloud-gateway,因为目前该工程还不能完全集成进项目去等集成完毕再放出来
上级
57217236
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
0 addition
and
338 deletion
+0
-338
README.md
README.md
+0
-1
zlt-gateway/pom.xml
zlt-gateway/pom.xml
+0
-1
zlt-gateway/spring-cloud-gateway/pom.xml
zlt-gateway/spring-cloud-gateway/pom.xml
+0
-70
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/ApiGateWayApp.java
...eway/src/main/java/com/central/gateway/ApiGateWayApp.java
+0
-16
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/client/config/CorsConfig.java
...in/java/com/central/gateway/client/config/CorsConfig.java
+0
-65
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/swagger/config/GatewaySwaggerProvider.java
...entral/gateway/swagger/config/GatewaySwaggerProvider.java
+0
-53
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/swagger/filter/GwSwaggerHeaderFilter.java
...central/gateway/swagger/filter/GwSwaggerHeaderFilter.java
+0
-31
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/swagger/handler/SwaggerHandler.java
...a/com/central/gateway/swagger/handler/SwaggerHandler.java
+0
-50
zlt-gateway/spring-cloud-gateway/src/main/resources/application.yml
...y/spring-cloud-gateway/src/main/resources/application.yml
+0
-32
zlt-gateway/spring-cloud-gateway/src/main/resources/bootstrap.yml
...way/spring-cloud-gateway/src/main/resources/bootstrap.yml
+0
-19
未找到文件。
README.md
浏览文件 @
548a5bb2
...
...
@@ -106,7 +106,6 @@ central-platform -- 父项目,公共依赖
│
├─
zlt
-
config
-- 配置中心
│
├─
zlt
-
doc
-- 项目文档
│
├─
zlt
-
gateway
-- api网关一级工程
│
│
├─
spring
-
cloud
-
gateway
-- 开发中..
│
│
├─
zuul
-
gateway
-- netflix-zuul[9900]
│
├─
zlt
-
job
-- 分布式任务调度一级工程
│
│
├─
job
-
admin
-- 任务管理器[8081]
...
...
zlt-gateway/pom.xml
浏览文件 @
548a5bb2
...
...
@@ -10,6 +10,5 @@
<packaging>
pom
</packaging>
<modules>
<module>
zuul-gateway
</module>
<module>
spring-cloud-gateway
</module>
</modules>
</project>
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/pom.xml
已删除
100644 → 0
浏览文件 @
57217236
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-gateway
</artifactId>
<version>
1.4.0
</version>
</parent>
<artifactId>
sc-gateway
</artifactId>
<description>
spring cloud gateway网关
</description>
<dependencies>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-config
</artifactId>
</dependency>
<!-- 加入redis的处理 -->
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-redis-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-webflux
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-gateway
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<!-- swagger -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>
${project.artifactId}
</finalName>
</build>
</project>
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/ApiGateWayApp.java
已删除
100644 → 0
浏览文件 @
57217236
package
com.central.gateway
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
/**
* @author zlt
*/
@EnableDiscoveryClient
@SpringBootApplication
public
class
ApiGateWayApp
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ApiGateWayApp
.
class
,
args
);
}
}
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/client/config/CorsConfig.java
已删除
100644 → 0
浏览文件 @
57217236
package
com.central.gateway.client.config
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator
;
import
org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties
;
import
org.springframework.cloud.gateway.route.RouteDefinitionLocator
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.codec.ServerCodecConfigurer
;
import
org.springframework.http.codec.support.DefaultServerCodecConfigurer
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.http.server.reactive.ServerHttpResponse
;
import
org.springframework.web.cors.reactive.CorsUtils
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.WebFilter
;
import
org.springframework.web.server.WebFilterChain
;
import
reactor.core.publisher.Mono
;
@Configuration
public
class
CorsConfig
{
private
static
final
String
ALL
=
"*"
;
private
static
final
String
MAX_AGE
=
"18000L"
;
@Bean
public
RouteDefinitionLocator
discoveryClientRouteDefinitionLocator
(
DiscoveryClient
discoveryClient
,
DiscoveryLocatorProperties
properties
)
{
return
new
DiscoveryClientRouteDefinitionLocator
(
discoveryClient
,
properties
);
}
@Bean
public
ServerCodecConfigurer
serverCodecConfigurer
()
{
return
new
DefaultServerCodecConfigurer
();
}
@Bean
public
WebFilter
corsFilter
()
{
return
(
ServerWebExchange
ctx
,
WebFilterChain
chain
)
->
{
ServerHttpRequest
request
=
ctx
.
getRequest
();
if
(!
CorsUtils
.
isCorsRequest
(
request
))
{
return
chain
.
filter
(
ctx
);
}
HttpHeaders
requestHeaders
=
request
.
getHeaders
();
ServerHttpResponse
response
=
ctx
.
getResponse
();
HttpMethod
requestMethod
=
requestHeaders
.
getAccessControlRequestMethod
();
HttpHeaders
headers
=
response
.
getHeaders
();
headers
.
add
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_ORIGIN
,
requestHeaders
.
getOrigin
());
headers
.
addAll
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_HEADERS
,
requestHeaders
.
getAccessControlRequestHeaders
());
if
(
requestMethod
!=
null
)
{
headers
.
add
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_METHODS
,
requestMethod
.
name
());
}
headers
.
add
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_CREDENTIALS
,
"true"
);
headers
.
add
(
HttpHeaders
.
ACCESS_CONTROL_EXPOSE_HEADERS
,
ALL
);
headers
.
add
(
HttpHeaders
.
ACCESS_CONTROL_MAX_AGE
,
MAX_AGE
);
if
(
request
.
getMethod
()
==
HttpMethod
.
OPTIONS
)
{
response
.
setStatusCode
(
HttpStatus
.
OK
);
return
Mono
.
empty
();
}
return
chain
.
filter
(
ctx
);
};
}
}
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/swagger/config/GatewaySwaggerProvider.java
已删除
100644 → 0
浏览文件 @
57217236
package
com.central.gateway.swagger.config
;
import
org.springframework.cloud.gateway.config.GatewayProperties
;
import
org.springframework.cloud.gateway.route.RouteLocator
;
import
org.springframework.cloud.gateway.support.NameUtils
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Component
;
import
springfox.documentation.swagger.web.SwaggerResource
;
import
springfox.documentation.swagger.web.SwaggerResourcesProvider
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @Primary注解的实例优先于其他实例被注入
*/
@Component
@Primary
public
class
GatewaySwaggerProvider
implements
SwaggerResourcesProvider
{
public
static
final
String
API_URI
=
"/v2/api-docs"
;
private
final
RouteLocator
routeLocator
;
private
final
GatewayProperties
gatewayProperties
;
public
GatewaySwaggerProvider
(
RouteLocator
routeLocator
,
GatewayProperties
gatewayProperties
)
{
this
.
routeLocator
=
routeLocator
;
this
.
gatewayProperties
=
gatewayProperties
;
}
@Override
public
List
<
SwaggerResource
>
get
()
{
List
<
SwaggerResource
>
resources
=
new
ArrayList
<>();
List
<
String
>
routes
=
new
ArrayList
<>();
//取出Spring Cloud Gateway中的route
routeLocator
.
getRoutes
().
subscribe
(
route
->
routes
.
add
(
route
.
getId
()));
//结合application.yml中的路由配置,只获取有效的route节点
gatewayProperties
.
getRoutes
().
stream
().
filter
(
routeDefinition
->
routes
.
contains
(
routeDefinition
.
getId
()))
.
forEach
(
routeDefinition
->
routeDefinition
.
getPredicates
().
stream
()
.
filter
(
predicateDefinition
->
(
"Path"
).
equalsIgnoreCase
(
predicateDefinition
.
getName
()))
.
forEach
(
predicateDefinition
->
resources
.
add
(
swaggerResource
(
routeDefinition
.
getId
(),
predicateDefinition
.
getArgs
().
get
(
NameUtils
.
GENERATED_NAME_PREFIX
+
"0"
)
.
replace
(
"/**"
,
API_URI
)))));
return
resources
;
}
private
SwaggerResource
swaggerResource
(
String
name
,
String
location
)
{
SwaggerResource
swaggerResource
=
new
SwaggerResource
();
swaggerResource
.
setName
(
name
);
swaggerResource
.
setLocation
(
location
);
swaggerResource
.
setSwaggerVersion
(
"2.0"
);
return
swaggerResource
;
}
}
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/swagger/filter/GwSwaggerHeaderFilter.java
已删除
100644 → 0
浏览文件 @
57217236
package
com.central.gateway.swagger.filter
;
import
org.springframework.cloud.gateway.filter.GatewayFilter
;
import
org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.server.ServerWebExchange
;
import
com.central.gateway.swagger.config.GatewaySwaggerProvider
;
@Component
public
class
GwSwaggerHeaderFilter
extends
AbstractGatewayFilterFactory
{
private
static
final
String
HEADER_NAME
=
"X-Forwarded-Prefix"
;
@Override
public
GatewayFilter
apply
(
Object
config
)
{
return
(
exchange
,
chain
)
->
{
ServerHttpRequest
request
=
exchange
.
getRequest
();
String
path
=
request
.
getURI
().
getPath
();
if
(!
StringUtils
.
endsWithIgnoreCase
(
path
,
GatewaySwaggerProvider
.
API_URI
))
{
return
chain
.
filter
(
exchange
);
}
String
basePath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
GatewaySwaggerProvider
.
API_URI
));
ServerHttpRequest
newRequest
=
request
.
mutate
().
header
(
HEADER_NAME
,
basePath
).
build
();
ServerWebExchange
newExchange
=
exchange
.
mutate
().
request
(
newRequest
).
build
();
return
chain
.
filter
(
newExchange
);
};
}
}
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/src/main/java/com/central/gateway/swagger/handler/SwaggerHandler.java
已删除
100644 → 0
浏览文件 @
57217236
package
com.central.gateway.swagger.handler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Optional
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
reactor.core.publisher.Mono
;
import
springfox.documentation.swagger.web.SecurityConfiguration
;
import
springfox.documentation.swagger.web.SecurityConfigurationBuilder
;
import
springfox.documentation.swagger.web.SwaggerResourcesProvider
;
import
springfox.documentation.swagger.web.UiConfiguration
;
import
springfox.documentation.swagger.web.UiConfigurationBuilder
;
@RestController
@RequestMapping
(
"/swagger-resources"
)
public
class
SwaggerHandler
{
@Autowired
(
required
=
false
)
private
SecurityConfiguration
securityConfiguration
;
@Autowired
(
required
=
false
)
private
UiConfiguration
uiConfiguration
;
private
final
SwaggerResourcesProvider
swaggerResources
;
@Autowired
public
SwaggerHandler
(
SwaggerResourcesProvider
swaggerResources
)
{
this
.
swaggerResources
=
swaggerResources
;
}
@GetMapping
(
"/configuration/security"
)
public
Mono
<
ResponseEntity
<
SecurityConfiguration
>>
securityConfiguration
()
{
return
Mono
.
just
(
new
ResponseEntity
<>(
Optional
.
ofNullable
(
securityConfiguration
).
orElse
(
SecurityConfigurationBuilder
.
builder
().
build
()),
HttpStatus
.
OK
));
}
@GetMapping
(
"/configuration/ui"
)
public
Mono
<
ResponseEntity
<
UiConfiguration
>>
uiConfiguration
()
{
return
Mono
.
just
(
new
ResponseEntity
<>(
Optional
.
ofNullable
(
uiConfiguration
).
orElse
(
UiConfigurationBuilder
.
builder
().
build
()),
HttpStatus
.
OK
));
}
@GetMapping
(
""
)
public
Mono
<
ResponseEntity
>
swaggerResources
()
{
return
Mono
.
just
((
new
ResponseEntity
<>(
swaggerResources
.
get
(),
HttpStatus
.
OK
)));
}
}
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/src/main/resources/application.yml
已删除
100644 → 0
浏览文件 @
57217236
spring
:
cloud
:
gateway
:
discovery
:
locator
:
lowerCaseServiceId
:
true
enabled
:
true
routes
:
# =====================================
-
id
:
api-user
uri
:
lb://user-center
order
:
8001
predicates
:
-
Path=/api-user/**
filters
:
-
GwSwaggerHeaderFilter
-
StripPrefix=1
-
id
:
api-uaa
uri
:
lb://uaa-server
order
:
8002
predicates
:
-
Path=/api-uaa/**
filters
:
-
GwSwaggerHeaderFilter
-
StripPrefix=1
-
id
:
api-file
uri
:
lb://file-center
order
:
8003
predicates
:
-
Path=/api-file/**
filters
:
-
StripPrefix=1
\ No newline at end of file
zlt-gateway/spring-cloud-gateway/src/main/resources/bootstrap.yml
已删除
100644 → 0
浏览文件 @
57217236
server
:
port
:
9900
zlt
:
nacos
:
server-addr
:
192.168.28.130:8848
spring
:
application
:
name
:
sc-gateway
cloud
:
nacos
:
config
:
server-addr
:
${zlt.nacos.server-addr}
file-extension
:
yml
shared-dataids
:
common.yml
refreshable-dataids
:
common.yml
discovery
:
server-addr
:
${zlt.nacos.server-addr}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录