修改代理服务

This commit is contained in:
haozq 2025-08-19 18:49:02 +08:00
parent 6eec973c2a
commit 1815b37547
7 changed files with 85 additions and 14 deletions

View File

@ -0,0 +1,31 @@
package com.bonus.gateway.config;
import java.util.ArrayList;
import java.util.List;
/**
* @author 黑子
*/
public class AuthWriteUtils {
public static List<String> getBlackUrl(){
List<String> whiteUrl=new ArrayList<>();
whiteUrl.add("/bmw/**");
return whiteUrl;
}
public static List<String> getWriteUrl(){
List<String> whiteUrl=new ArrayList<>();
whiteUrl.add("js");
whiteUrl.add("ttf");
whiteUrl.add("woff2");
whiteUrl.add("woff");
whiteUrl.add("ico");
whiteUrl.add("css");
whiteUrl.add("png");
whiteUrl.add("jpg");
whiteUrl.add("html");
return whiteUrl;
}
}

View File

@ -0,0 +1,26 @@
package com.bonus.gateway.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* description:
* java项目fhadmin.cn
*/
@Configuration
public class CorsConfig {
@Bean
public CorsWebFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedMethod("*"); // 是什么请求方法比如GET POST PUT DELATE ...
config.addAllowedOrigin("*"); // 来自哪个域名的请求*号表示所有
config.addAllowedOriginPattern("*"); // 来自哪个域名的请求*号表示所有
config.addAllowedHeader("*"); // 是什么请求头部
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
}

View File

@ -1,5 +1,6 @@
package com.bonus.gateway.filter; package com.bonus.gateway.filter;
import com.bonus.gateway.config.AuthWriteUtils;
import com.bonus.gateway.config.properties.IgnoreWhiteProperties; import com.bonus.gateway.config.properties.IgnoreWhiteProperties;
import com.bonus.common.core.constant.CacheConstants; import com.bonus.common.core.constant.CacheConstants;
import com.bonus.common.core.constant.HttpStatus; import com.bonus.common.core.constant.HttpStatus;
@ -44,8 +45,18 @@ public class AuthFilter implements GlobalFilter, Ordered
{ {
ServerHttpRequest request = exchange.getRequest(); ServerHttpRequest request = exchange.getRequest();
ServerHttpRequest.Builder mutate = request.mutate(); ServerHttpRequest.Builder mutate = request.mutate();
String url = request.getURI().getPath(); String url = request.getURI().getPath();
if (StringUtils.matches(url, AuthWriteUtils.getBlackUrl()))
{
if(url.contains(".")){
String type=url.substring(url.lastIndexOf(".")+1).toLowerCase().trim();
if(AuthWriteUtils.getWriteUrl().contains(type)){
return chain.filter(exchange);
}
}
}
// 跳过不需要验证的路径 // 跳过不需要验证的路径
if (StringUtils.matches(url, ignoreWhite.getWhites())) if (StringUtils.matches(url, ignoreWhite.getWhites()))
{ {

View File

@ -13,8 +13,8 @@ server:
buffered: true buffered: true
requestAttributesEnabled: true requestAttributesEnabled: true
port: 1911 port: 1911
servlet: # servlet:
context-path: /bmw # context-path: /bmw
environment: @profiles.active@ environment: @profiles.active@

View File

@ -125,7 +125,7 @@ function logout() {
$.ajax({ $.ajax({
type: 'delete', type: 'delete',
url: loginPath + '/logout', url: DATA_URL + '/auth/logout',
headers: { headers: {
"Authorization": token "Authorization": token
}, },

View File

@ -1,16 +1,19 @@
var ctxPath = getContextPath(); let DATA_URL="http://127.0.0.1:9100"
var ctxPath = "http://127.0.0.1:9100/bmw"
var currentHostname = window.location.hostname; var currentHostname = window.location.hostname;
// //测试 // //测试
// var loginPath = "http://" + currentHostname + ":9200"; // var loginPath = "http://" + currentHostname + ":9200";
// var systemPath = "http://" + currentHostname + ":1910"; // var systemPath = "http://" + currentHostname + ":1910";
var loginPath = "http://" + currentHostname + ":1616/auth";
var systemPath = "http://" + currentHostname + ":1616/system"; var systemPath = "http://" + currentHostname + ":9100/system";
var filePath = "http://" + currentHostname + ":1909/file"; var filePath = "http://" + currentHostname + ":9100/file";
var fileUrl = "http://" + currentHostname + ":1909/file"; var fileUrl = "http://" + currentHostname + ":9100/file";
var planUrl = "http://" + currentHostname + ":1918/ynPlan"; var planUrl = "http://" + currentHostname + ":9100/ynPlan";
var oiPlanUrl = "http://" + currentHostname + ":1914/oiPlan"; var oiPlanUrl = "http://" + currentHostname + ":9100/oiPlan";
//112.29.103.165:1616 //112.29.103.165:1616
//正式环境 //正式环境

View File

@ -72,7 +72,7 @@
if (token != null && token.trim().length != 0) { if (token != null && token.trim().length != 0) {
$.ajax({ $.ajax({
type : 'get', type : 'get',
url : ctxPath + '/users/current?token=' + token, url : DATA_URL + '/users/current?token=' + token,
success : function(data) { success : function(data) {
if(data != ''){ if(data != ''){
location.href = ctxPath + '/index.html'; location.href = ctxPath + '/index.html';
@ -107,7 +107,7 @@
$.ajax({ $.ajax({
type : 'post', type : 'post',
contentType : "application/json; charset=utf-8", contentType : "application/json; charset=utf-8",
url : loginPath + '/login', url : DATA_URL + '/auth/login',
data : JSON.stringify({ data : JSON.stringify({
// "username" : username, // "username" : username,
// "password" : password, // "password" : password,
@ -209,7 +209,7 @@
time:5000 time:5000
}); });
} }
var url = loginPath+"/getTokenKey?jwtToken="+jwtToken; var url = ctxPath+"/auth/getTokenKey?jwtToken="+jwtToken;
$.ajax({ $.ajax({
type : "GET", type : "GET",
contentType: "application/json;charset=UTF-8", contentType: "application/json;charset=UTF-8",