diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/controller/RestfulController.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/controller/RestfulController.java index dcad45ad..6f04187e 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/controller/RestfulController.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/controller/RestfulController.java @@ -2,6 +2,7 @@ package com.gitee.sop.gatewaycommon.gateway.controller; import com.gitee.sop.gatewaycommon.bean.SpringContext; import com.gitee.sop.gatewaycommon.gateway.loadbalancer.SopLoadBalancerClient; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.gateway.webflux.ProxyExchange; import org.springframework.http.ResponseEntity; @@ -18,9 +19,10 @@ import reactor.core.publisher.Mono; @Controller public class RestfulController { - private static final int PREFIX_LEN = "/rest/".length(); + @Value("${sop.restful.path:/rest}") + private String prefix; - @RequestMapping("/rest/**") + @RequestMapping("${sop.restful.path:/rest}/**") public Mono> proxy(ProxyExchange proxy, ServerWebExchange exchange) { String path = proxy.path(); String serviceId = getServiceId(path); @@ -41,14 +43,16 @@ public class RestfulController { * @return 返回serviceId */ private String getServiceId(String path) { - path = path.substring(PREFIX_LEN); + int length = prefix.length() + 1; + path = path.substring(length); int index = path.indexOf('/'); path = path.substring(0, index); return path; } private String getTargetPath(String serviceId, String path) { - int len = PREFIX_LEN + serviceId.length(); + int length = prefix.length() + 1; + int len = length + serviceId.length(); return path.substring(len); } } diff --git a/sop-gateway/src/main/resources/META-INF/gateway.properties b/sop-gateway/src/main/resources/META-INF/gateway.properties index f4570497..652167d2 100644 --- a/sop-gateway/src/main/resources/META-INF/gateway.properties +++ b/sop-gateway/src/main/resources/META-INF/gateway.properties @@ -1,38 +1,41 @@ -# 固定不变,不能改 +# \u56FA\u5B9A\u4E0D\u53D8\uFF0C\u4E0D\u80FD\u6539 spring.application.name=sop-gateway -# 不用改,如果要改,请全局替换修改 +# \u4E0D\u7528\u6539\uFF0C\u5982\u679C\u8981\u6539\uFF0C\u8BF7\u5168\u5C40\u66FF\u6362\u4FEE\u6539 sop.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC -# 文件上传配置 +# \u6587\u4EF6\u4E0A\u4F20\u914D\u7F6E spring.servlet.multipart.enabled=true spring.servlet.multipart.max-file-size=10MB -# 网关入口 +# \u7F51\u5173\u5165\u53E3 sop.gateway-index-path=/ -# 开启restful请求,默认开启 +# \u5F00\u542Frestful\u8BF7\u6C42\uFF0C\u9ED8\u8BA4\u5F00\u542F sop.restful.enable=true -# nacos cloud配置 +# restful\u8BF7\u6C42\u524D\u7F00 +sop.restful.path=/rest + +# nacos cloud\u914D\u7F6E spring.cloud.nacos.discovery.server-addr=${register.url} -# eureka地址 +# eureka\u5730\u5740 eureka.client.serviceUrl.defaultZone=${register.url} -# 数据库配置 +# \u6570\u636E\u5E93\u914D\u7F6E spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://${mysql.host}/sop?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai spring.datasource.username=${mysql.username} spring.datasource.password=${mysql.password} -#连接池 +#\u8FDE\u63A5\u6C60 spring.datasource.hikari.pool-name=HikariCP spring.datasource.hikari.max-lifetime=500000 spring.cloud.gateway.discovery.locator.lower-case-service-id=true spring.cloud.gateway.discovery.locator.enabled=true -# 不用改 +# \u4E0D\u7528\u6539 mybatis.mapper-locations=classpath:mybatis/mapper/*.xml mybatis.fill.com.gitee.fastmybatis.core.support.DateFillInsert=gmt_create mybatis.fill.com.gitee.fastmybatis.core.support.DateFillUpdate=gmt_modified