设置路由
This commit is contained in:
parent
9a08de16eb
commit
fe1a976732
@ -2,8 +2,10 @@ package com.qiuguo.iot.gateway;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
public class GatewayApplication {
|
public class GatewayApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@ -37,30 +37,28 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
String url = request.getPath().toString();
|
String url = request.getPath().toString();
|
||||||
System.out.println("url = " + url);
|
if (xssProperties.getExcludeUrls().contains(url)) {
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
// if (xssProperties.getExcludeUrls().contains(url)) {
|
}
|
||||||
// return chain.filter(exchange);
|
|
||||||
// }
|
String api_token = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TOKEN);
|
||||||
//
|
String api_type = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TYPE);
|
||||||
// String api_token = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TOKEN);
|
if (ObjectUtils.isEmpty(api_token) || ObjectUtils.isEmpty(api_type)) {
|
||||||
// String api_type = exchange.getRequest().getHeaders().getFirst(UserAuthContains.API_TYPE);
|
return Mono.error(new RuntimeException("未登录"));
|
||||||
// if (ObjectUtils.isEmpty(api_token) || ObjectUtils.isEmpty(api_type)) {
|
}
|
||||||
// return Mono.error(new RuntimeException("未登录"));
|
String key = RedisConstans.IOT_TOKEN.concat(api_token);
|
||||||
// }
|
return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
|
||||||
// String key = RedisConstans.IOT_TOKEN.concat(api_token);
|
if (ttl == -1) {
|
||||||
// return reactiveRedisTemplate.getExpire(key).map(Duration::getSeconds).flatMap(ttl -> {
|
// 用户没登陆
|
||||||
// if (ttl == -1) {
|
return Mono.error(new RuntimeException("未登录"));
|
||||||
// // 用户没登陆
|
} else if (ttl <= 3600) {
|
||||||
// return Mono.error(new RuntimeException("未登录"));
|
// token 将要失效
|
||||||
// } else if (ttl <= 3600) {
|
return reactiveRedisTemplate.expire(key, Duration.ofDays(7)).then(chain.filter(exchange));
|
||||||
// // token 将要失效
|
} else {
|
||||||
// return reactiveRedisTemplate.expire(key, Duration.ofDays(7)).then(chain.filter(exchange));
|
// 正常登录
|
||||||
// } else {
|
return chain.filter(exchange);
|
||||||
// // 正常登录
|
}
|
||||||
// return chain.filter(exchange);
|
});
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,8 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
|
|||||||
} else if (ex instanceof ResponseStatusException) {
|
} else if (ex instanceof ResponseStatusException) {
|
||||||
ResponseStatusException responseStatusException = (ResponseStatusException) ex;
|
ResponseStatusException responseStatusException = (ResponseStatusException) ex;
|
||||||
msg = responseStatusException.getMessage();
|
msg = responseStatusException.getMessage();
|
||||||
|
} else if (ex instanceof RuntimeException) {
|
||||||
|
msg = ex.getMessage();
|
||||||
} else {
|
} else {
|
||||||
msg = "内部服务器错误";
|
msg = "内部服务器错误";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,13 @@ spring:
|
|||||||
password: 123456
|
password: 123456
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
cloud:
|
cloud:
|
||||||
# config:
|
config:
|
||||||
# # 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
# 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||||
# override-none: true
|
override-none: true
|
||||||
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
# 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||||
# allow-override: true
|
allow-override: true
|
||||||
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||||
# override-system-properties: false
|
override-system-properties: false
|
||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
@ -25,12 +25,14 @@ spring:
|
|||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
gateway:
|
gateway:
|
||||||
discovery:
|
routes:
|
||||||
locator:
|
- id: qiuguo-iot-box-user-api
|
||||||
# 开启服务发现
|
uri: lb://qiuguo-iot-box-user-api
|
||||||
enabled: true
|
predicates:
|
||||||
# 忽略注册中心服务的大小写
|
- Path=/iot-user/**
|
||||||
lower-case-service-id: true
|
filters:
|
||||||
|
# 转发时去掉一层路径
|
||||||
|
- StripPrefix=1
|
||||||
globalcors:
|
globalcors:
|
||||||
corsConfigurations:
|
corsConfigurations:
|
||||||
'[/**]':
|
'[/**]':
|
||||||
@ -42,22 +44,6 @@ spring:
|
|||||||
allowedMethods: "*"
|
allowedMethods: "*"
|
||||||
# 允许跨域请求里的head字段,设置*为全部
|
# 允许跨域请求里的head字段,设置*为全部
|
||||||
allowedHeaders: "*"
|
allowedHeaders: "*"
|
||||||
routes:
|
|
||||||
# # 系统服务
|
|
||||||
# - id: qiuguo-iot-box-user-api
|
|
||||||
# # 匹配后路由地址
|
|
||||||
# uri: lb://qiuguo-iot-box-user-api
|
|
||||||
# # 断言,路径相匹配的进行路由
|
|
||||||
# predicates:
|
|
||||||
# - Path=/qiuguo-iot-box-user-api/**
|
|
||||||
# filters:
|
|
||||||
# # 转发时去掉一层路径
|
|
||||||
# - StripPrefix=1
|
|
||||||
- id: route_qiuguo-iot-box-user-api
|
|
||||||
uri: lb://qiuguo-iot-box-user-api
|
|
||||||
predicates:
|
|
||||||
- Path=/**
|
|
||||||
|
|
||||||
# 安全配置
|
# 安全配置
|
||||||
security:
|
security:
|
||||||
# 防止XSS攻击
|
# 防止XSS攻击
|
||||||
@ -65,7 +51,7 @@ security:
|
|||||||
enabled: true
|
enabled: true
|
||||||
# 排除的路径
|
# 排除的路径
|
||||||
exclude-urls:
|
exclude-urls:
|
||||||
- /iot-user/user/user/login/pwd
|
- /iot-user/user/login/pwd
|
||||||
#application:
|
#application:
|
||||||
# cors:
|
# cors:
|
||||||
# allowed-crigin-patterns:
|
# allowed-crigin-patterns:
|
||||||
|
|||||||
@ -4,12 +4,14 @@ import com.tuya.connector.spring.annotations.ConnectorScan;
|
|||||||
import org.hswebframework.web.crud.annotation.EnableEasyormRepository;
|
import org.hswebframework.web.crud.annotation.EnableEasyormRepository;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"com.qiuguo.iot.user.api", "com.qiuguo.iot.data.service"})
|
@SpringBootApplication(scanBasePackages = {"com.qiuguo.iot.user.api", "com.qiuguo.iot.data.service"})
|
||||||
@EnableEasyormRepository(value = "com.qiuguo.iot.data.entity.*")
|
@EnableEasyormRepository(value = "com.qiuguo.iot.data.entity.*")
|
||||||
@ConnectorScan(basePackages = "com.qiuguo.iot.user.api.service")
|
@ConnectorScan(basePackages = "com.qiuguo.iot.user.api.service")
|
||||||
@EnableAspectJAutoProxy
|
@EnableAspectJAutoProxy
|
||||||
|
@EnableDiscoveryClient
|
||||||
public class IotBoxUserApiApplication {
|
public class IotBoxUserApiApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user