访问通过gateway的一些小修改

This commit is contained in:
方亮 2025-10-10 15:10:21 +08:00
parent d8b45c99be
commit b44cca031a
6 changed files with 56 additions and 75 deletions

View File

@ -1,42 +1,42 @@
package com.bonus.gateway.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.server.WebFilter;
/**
* @author HeiZi
*/
@Configuration
public class ContextPathConfig {
@Bean
@ConditionalOnProperty("server.servlet.context-path")
@Order(Ordered.HIGHEST_PRECEDENCE)
public WebFilter contextPathWebFilter(ServerProperties serverProperties){
String contextPath = serverProperties.getServlet().getContextPath();
return (serverWebExchange, webFilterChain) ->{
ServerHttpRequest request = serverWebExchange.getRequest();
String requestPath = request.getURI().getPath();
if(requestPath.contains(contextPath)){
String newPath = requestPath.replaceFirst(contextPath+"/", "");
ServerHttpRequest newRequest = request.mutate()
.path(newPath).build();
return webFilterChain.filter(serverWebExchange.mutate()
.request(newRequest)
.build()
);
}else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
};
}
}
//package com.bonus.gateway.config;
//
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.autoconfigure.web.ServerProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.Ordered;
//import org.springframework.core.annotation.Order;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.web.server.ResponseStatusException;
//import org.springframework.web.server.WebFilter;
//
///**
// * @author HeiZi
// */
//@Configuration
//public class ContextPathConfig {
//
// @Bean
// @ConditionalOnProperty("server.servlet.context-path")
// @Order(Ordered.HIGHEST_PRECEDENCE)
// public WebFilter contextPathWebFilter(ServerProperties serverProperties){
// String contextPath = serverProperties.getServlet().getContextPath();
// return (serverWebExchange, webFilterChain) ->{
// ServerHttpRequest request = serverWebExchange.getRequest();
// String requestPath = request.getURI().getPath();
//
// if(requestPath.contains(contextPath)){
// String newPath = requestPath.replaceFirst(contextPath+"/", "");
// ServerHttpRequest newRequest = request.mutate()
// .path(newPath).build();
// return webFilterChain.filter(serverWebExchange.mutate()
// .request(newRequest)
// .build()
// );
// }else {
// throw new ResponseStatusException(HttpStatus.NOT_FOUND);
// }
// };
// }
//}

View File

@ -1,10 +1,10 @@
# Tomcat
server:
port: 9101
servlet:
context-path: ynRealName
# servlet:
# context-path: ynRealName
# Spring
spring:
spring:
application:
# 应用名称
name: gateway
@ -32,9 +32,9 @@ spring:
sentinel:
# 取消控制台懒加载
eager: true
transport:
# 控制台地址
server-addr: @nacos.server@
# transport:
# # 控制台地址
# server-addr: @nacos.server@
# nacos配置持久化
datasource:
ds1:
@ -54,4 +54,4 @@ management:
enabled-by-default: false
endpoint:
beans:
enabled: false
enabled: false

View File

@ -16,7 +16,6 @@ server:
# servlet:
# context-path: /bmw
environment: @profiles.active@
## Spring
spring:

View File

@ -1,33 +1,15 @@
//测试路径
let host=window.location.host;
let IP_URL="https://"+host+"/ynRealName";
//let IP_URL="http://192.168.0.7:9101/ynRealName"
//本地ip
//let IP_URL="http://127.0.0.1:9101/ynRealName"
let IP_URL="http://"+host;
var ctxPath = IP_URL+"/bmw";
var currentHostname = window.location.hostname;
var currentHostname2 = window.location.host;
console.log(currentHostname+":"+currentHostname2)
// //测试
// var loginPath = "http://" + currentHostname + ":9200";
// var systemPath = "http://" + currentHostname + ":1910";
var filePath =IP_URL + "/file";
var fileUrl =IP_URL +"/file";
var oiPlanUrl = IP_URL + "/oiPlan";
//112.29.103.165:1616
//正式环境
// var loginPath = "http://" + currentHostname + ":1616/auth";
// var systemPath = "http://" + currentHostname + ":1616/system";
// var filePath = "http://" + currentHostname + ":1616/file";
// var fileUrl = "http://" + currentHostname + ":1616/file";
// var planUrl = "http://" + currentHostname + ":1616/ynPlan";
// var oiPlanUrl = "http://" + currentHostname + ":1616/oiPlan";
//文件预览
// let filePreviewUrl = "http://192.168.0.14:8012/onlinePreview?url=";
let filePreviewUrl = "http://" + currentHostname + ":8012/onlinePreview?url=";
function getContextPath() {
@ -65,4 +47,4 @@ function isWeakPassword(password) {
}else{
return false;
}
}
}

View File

@ -130,7 +130,7 @@ function photoView(idNumber) {
}
function exportList(id) {
location.href = ctxPath + '/salaryBookFill/exportExamList?id='+ id;
location.href = ctxPath + '/salaryBookFill/exportExamList?id='+ id + '&token='+ localStorage.getItem("smz-token");
}
// 编辑按钮
@ -155,4 +155,4 @@ function buttonExport(id, permission, pers) {
function buttonView(id,permission, pers) {
var btn = $("<button class='layui-btn layui-btn-xs' title='删除' onclick='photoView(\"" + id + "\")'>查看</button>");
return btn.prop("outerHTML");
}
}

View File

@ -245,7 +245,7 @@ function dataEdit(idNumber) {
function exportList(id) {
location.href = ctxPath + '/salaryBookFill/exportExamList?id='+ id;
location.href = ctxPath + '/salaryBookFill/exportExamList?id='+ id + '&token='+ localStorage.getItem("smz-token");
}
function submit(id) {
@ -355,4 +355,4 @@ function reloading() {
var index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
window.parent.location.reload();
}
}