mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-03-05 10:05:45 +08:00
反向代理支持RequestPath、RequestURI等
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
@@ -40,6 +39,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
@@ -47,10 +47,9 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Data["serverType"] = serverType
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
primaryOriginMaps := []maps.Map{}
|
||||
backupOriginMaps := []maps.Map{}
|
||||
@@ -75,23 +74,3 @@ func (this *IndexAction) RunGet(params struct {
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
LocationId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// TODO 校验配置
|
||||
|
||||
_, err := this.RPC().HTTPLocationRPC().UpdateHTTPLocationReverseProxy(this.AdminContext(), &pb.UpdateHTTPLocationReverseProxyRequest{
|
||||
LocationId: params.LocationId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ func init() {
|
||||
Data("mainTab", "setting").
|
||||
Data("tinyMenuItem", "reverseProxy").
|
||||
Prefix("/servers/server/settings/locations/reverseProxy").
|
||||
GetPost("", new(IndexAction)).
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/scheduling", new(SchedulingAction)).
|
||||
GetPost("/setting", new(SettingAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.FirstMenu("setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct {
|
||||
LocationId int64
|
||||
}) {
|
||||
reverseProxyResp, err := this.RPC().HTTPLocationRPC().FindAndInitHTTPLocationReverseProxyConfig(this.AdminContext(), &pb.FindAndInitHTTPLocationReverseProxyConfigRequest{LocationId: params.LocationId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
LocationId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
ReverseProxyJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// TODO 校验配置
|
||||
|
||||
reverseProxyConfig := &serverconfigs.ReverseProxyConfig{}
|
||||
err := json.Unmarshal(params.ReverseProxyJSON, reverseProxyConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置是否启用
|
||||
_, err = this.RPC().HTTPLocationRPC().UpdateHTTPLocationReverseProxy(this.AdminContext(), &pb.UpdateHTTPLocationReverseProxyRequest{
|
||||
LocationId: params.LocationId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置反向代理相关信息
|
||||
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
|
||||
ReverseProxyId: reverseProxyConfig.Id,
|
||||
RequestHost: reverseProxyConfig.RequestHost,
|
||||
RequestURI: reverseProxyConfig.RequestURI,
|
||||
StripPrefix: reverseProxyConfig.StripPrefix,
|
||||
})
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
@@ -39,6 +38,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
@@ -46,10 +46,9 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Data["serverType"] = serverType
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
primaryOriginMaps := []maps.Map{}
|
||||
backupOriginMaps := []maps.Map{}
|
||||
@@ -74,23 +73,3 @@ func (this *IndexAction) RunGet(params struct {
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
ServerId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// TODO 校验配置
|
||||
|
||||
_, err := this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{
|
||||
ServerId: params.ServerId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ func init() {
|
||||
Data("mainTab", "setting").
|
||||
Data("secondMenuItem", "reverseProxy").
|
||||
Prefix("/servers/server/settings/reverseProxy").
|
||||
GetPost("", new(IndexAction)).
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/scheduling", new(SchedulingAction)).
|
||||
GetPost("/updateSchedulingPopup", new(UpdateSchedulingPopupAction)).
|
||||
Post("/updateOn", new(UpdateOnAction)).
|
||||
GetPost("/setting", new(SettingAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.FirstMenu("setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
}) {
|
||||
reverseProxyResp, err := this.RPC().ServerRPC().FindAndInitServerReverseProxyConfig(this.AdminContext(), &pb.FindAndInitServerReverseProxyConfigRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxy := &serverconfigs.ReverseProxyConfig{}
|
||||
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["reverseProxyRef"] = reverseProxyRef
|
||||
this.Data["reverseProxyConfig"] = reverseProxy
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
ServerId int64
|
||||
ReverseProxyRefJSON []byte
|
||||
ReverseProxyJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// TODO 校验配置
|
||||
|
||||
reverseProxyConfig := &serverconfigs.ReverseProxyConfig{}
|
||||
err := json.Unmarshal(params.ReverseProxyJSON, reverseProxyConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置是否启用
|
||||
_, err = this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{
|
||||
ServerId: params.ServerId,
|
||||
ReverseProxyJSON: params.ReverseProxyRefJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置反向代理相关信息
|
||||
_, err = this.RPC().ReverseProxyRPC().UpdateReverseProxy(this.AdminContext(), &pb.UpdateReverseProxyRequest{
|
||||
ReverseProxyId: reverseProxyConfig.Id,
|
||||
RequestHost: reverseProxyConfig.RequestHost,
|
||||
RequestURI: reverseProxyConfig.RequestURI,
|
||||
StripPrefix: reverseProxyConfig.StripPrefix,
|
||||
})
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
type UpdateOnAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateOnAction) RunPost(params struct {
|
||||
ServerId int64
|
||||
ReverseProxyId int64
|
||||
IsOn bool
|
||||
}) {
|
||||
// 如果没有配置过,则配置
|
||||
if params.ReverseProxyId <= 0 {
|
||||
if !params.IsOn {
|
||||
this.Success()
|
||||
}
|
||||
|
||||
resp, err := this.RPC().ReverseProxyRPC().CreateReverseProxy(this.AdminContext(), &pb.CreateReverseProxyRequest{
|
||||
SchedulingJSON: nil,
|
||||
PrimaryOriginsJSON: nil,
|
||||
BackupOriginsJSON: nil,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
reverseProxyId := resp.ReverseProxyId
|
||||
ref := &serverconfigs.ReverseProxyRef{
|
||||
IsOn: true,
|
||||
ReverseProxyId: reverseProxyId,
|
||||
}
|
||||
refJSON, err := json.Marshal(ref)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{
|
||||
ServerId: params.ServerId,
|
||||
ReverseProxyJSON: refJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
// 如果已经配置过
|
||||
_, err := this.RPC().ReverseProxyRPC().UpdateReverseProxyIsOn(this.AdminContext(), &pb.UpdateReverseProxyIsOnRequest{
|
||||
ReverseProxyId: params.ReverseProxyId,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user