feat: nacos调整
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: qing-yu-club-auth
|
||||
name: qing-yu-club-auth-dev
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
|
@@ -0,0 +1,46 @@
|
||||
package com.landaiqing.club.gateway.filter;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @Classname LoginFilter
|
||||
* @BelongsProject: qing-yu-club
|
||||
* @BelongsPackage: com.landaiqing.club.gateway.filter
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-03-03 17:41
|
||||
* @Description: 登录拦截器
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LoginFilter implements GlobalFilter {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
ServerHttpRequest.Builder mutate = request.mutate();
|
||||
String url = request.getURI().getPath();
|
||||
log.info("LoginFilter.filter.url:{}", url);
|
||||
if (url.equals("/auth/user/doLogin")) {
|
||||
chain.filter(exchange);
|
||||
}
|
||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||
String loginId = (String) tokenInfo.getLoginId();
|
||||
if (StringUtils.isEmpty(loginId)) {
|
||||
throw new Exception("未获取到用户信息");
|
||||
}
|
||||
mutate.header("loginId", loginId);
|
||||
|
||||
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||
}
|
||||
}
|
@@ -5,19 +5,19 @@ spring:
|
||||
gateway:
|
||||
routes:
|
||||
- id: oss
|
||||
uri: lb://qing-yu-club-oss
|
||||
uri: lb://qing-yu-club-oss-dev
|
||||
predicates:
|
||||
- Path=/oss/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: auth
|
||||
uri: lb://qing-yu-club-auth
|
||||
uri: lb://qing-yu-club-auth-dev
|
||||
predicates:
|
||||
- Path=/auth/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
- id: subject
|
||||
uri: lb://qing-yu-club-subject
|
||||
uri: lb://qing-yu-club-subject-dev
|
||||
predicates:
|
||||
- Path=/subject/**
|
||||
filters:
|
||||
|
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: qing-yu-club-oss
|
||||
name: qing-yu-club-oss-dev
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
|
@@ -1,6 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: qing-yu-club-subject
|
||||
name: qing-yu-club-subject-dev
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
|
Reference in New Issue
Block a user