优化界面

This commit is contained in:
GoEdgeLab
2021-06-07 16:23:37 +08:00
parent b13f9c5dfe
commit b3d3f251b3
3 changed files with 68 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"net/url"
"regexp"
"strings"
)
@@ -36,10 +37,27 @@ func (this *AddOriginPopupAction) RunPost(params struct {
Field("addr", params.Addr).
Require("请输入源站地址")
addr := regexp.MustCompile(`\s+`).ReplaceAllString(params.Addr, "")
portIndex := strings.LastIndex(params.Addr, ":")
addr := params.Addr
// 是否是完整的地址
if (params.Protocol == "http" || params.Protocol == "https") && regexp.MustCompile(`^(http|https)://`).MatchString(addr) {
u, err := url.Parse(addr)
if err == nil {
addr = u.Host
}
}
addr = regexp.MustCompile(`\s+`).ReplaceAllString(addr, "")
portIndex := strings.LastIndex(addr, ":")
if portIndex < 0 {
this.Fail("地址中需要带有端口")
if params.Protocol == "http" {
addr += ":80"
} else if params.Protocol == "https" {
addr += ":443"
} else {
this.Fail("地址中需要带有端口")
}
portIndex = strings.LastIndex(addr, ":")
}
host := addr[:portIndex]
port := addr[portIndex+1:]