反向代理支持RequestPath、RequestURI等

This commit is contained in:
GoEdgeLab
2020-09-27 10:03:05 +08:00
parent 40510293ce
commit 823ea3a82d
3 changed files with 22 additions and 7 deletions

View File

@@ -93,6 +93,9 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(reverseProxyId int64) (*s
config := &serverconfigs.ReverseProxyConfig{}
config.Id = int64(reverseProxy.Id)
config.IsOn = reverseProxy.IsOn == 1
config.RequestHost = reverseProxy.RequestHost
config.RequestURI = reverseProxy.RequestURI
config.StripPrefix = reverseProxy.StripPrefix
schedulingConfig := &serverconfigs.SchedulingConfig{}
if len(reverseProxy.Scheduling) > 0 && reverseProxy.Scheduling != "null" {
@@ -213,11 +216,17 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(reverseProxyId int6
}
// 修改是否启用
func (this *ReverseProxyDAO) UpdateReverseProxyIsOn(reverseProxyId int64, isOn bool) error {
_, err := this.Query().
Pk(reverseProxyId).
Set("isOn", isOn).
Update()
func (this *ReverseProxyDAO) UpdateReverseProxy(reverseProxyId int64, requestHost string, requestURI string, stripPrefix string) error {
if reverseProxyId <= 0 {
return errors.New("invalid reverseProxyId")
}
op := NewReverseProxyOperator()
op.Id = reverseProxyId
op.RequestHost = requestHost
op.RequestURI = requestURI
op.StripPrefix = stripPrefix
_, err := this.Save(op)
return err
}

View File

@@ -10,6 +10,9 @@ type ReverseProxy struct {
Scheduling string `field:"scheduling"` // 调度算法
PrimaryOrigins string `field:"primaryOrigins"` // 主要源站
BackupOrigins string `field:"backupOrigins"` // 备用源站
StripPrefix string `field:"stripPrefix"` // 去除URL前缀
RequestHost string `field:"requestHost"` // 请求Host
RequestURI string `field:"requestURI"` // 请求URI
State uint8 `field:"state"` // 状态
CreatedAt uint64 `field:"createdAt"` // 创建时间
}
@@ -23,6 +26,9 @@ type ReverseProxyOperator struct {
Scheduling interface{} // 调度算法
PrimaryOrigins interface{} // 主要源站
BackupOrigins interface{} // 备用源站
StripPrefix interface{} // 去除URL前缀
RequestHost interface{} // 请求Host
RequestURI interface{} // 请求URI
State interface{} // 状态
CreatedAt interface{} // 创建时间
}

View File

@@ -122,14 +122,14 @@ func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Con
}
// 修改是否启用
func (this *ReverseProxyService) UpdateReverseProxyIsOn(ctx context.Context, req *pb.UpdateReverseProxyIsOnRequest) (*pb.RPCUpdateSuccess, error) {
func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb.UpdateReverseProxyRequest) (*pb.RPCUpdateSuccess, error) {
// 校验请求
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
if err != nil {
return nil, err
}
err = models.SharedReverseProxyDAO.UpdateReverseProxyIsOn(req.ReverseProxyId, req.IsOn)
err = models.SharedReverseProxyDAO.UpdateReverseProxy(req.ReverseProxyId, req.RequestHost, req.RequestURI, req.StripPrefix)
if err != nil {
return nil, err
}