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

View File

@ -1,8 +1,8 @@
# Tomcat # Tomcat
server: server:
port: 9101 port: 9101
servlet: # servlet:
context-path: ynRealName # context-path: ynRealName
# Spring # Spring
spring: spring:
application: application:
@ -32,9 +32,9 @@ spring:
sentinel: sentinel:
# 取消控制台懒加载 # 取消控制台懒加载
eager: true eager: true
transport: # transport:
# 控制台地址 # # 控制台地址
server-addr: @nacos.server@ # server-addr: @nacos.server@
# nacos配置持久化 # nacos配置持久化
datasource: datasource:
ds1: ds1:

View File

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

View File

@ -1,33 +1,15 @@
//测试路径 //测试路径
let host=window.location.host; let host=window.location.host;
let IP_URL="https://"+host+"/ynRealName"; let IP_URL="http://"+host;
//let IP_URL="http://192.168.0.7:9101/ynRealName"
//本地ip
//let IP_URL="http://127.0.0.1:9101/ynRealName"
var ctxPath = IP_URL+"/bmw"; var ctxPath = IP_URL+"/bmw";
var currentHostname = window.location.hostname; 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 filePath =IP_URL + "/file";
var fileUrl =IP_URL +"/file"; var fileUrl =IP_URL +"/file";
var oiPlanUrl = IP_URL + "/oiPlan"; 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="; let filePreviewUrl = "http://" + currentHostname + ":8012/onlinePreview?url=";
function getContextPath() { function getContextPath() {

View File

@ -130,7 +130,7 @@ function photoView(idNumber) {
} }
function exportList(id) { function exportList(id) {
location.href = ctxPath + '/salaryBookFill/exportExamList?id='+ id; location.href = ctxPath + '/salaryBookFill/exportExamList?id='+ id + '&token='+ localStorage.getItem("smz-token");
} }
// 编辑按钮 // 编辑按钮

View File

@ -245,7 +245,7 @@ function dataEdit(idNumber) {
function exportList(id) { 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) { function submit(id) {