路由规则增加专属域名设置

This commit is contained in:
GoEdgeLab
2021-12-12 16:38:52 +08:00
parent dcaefa59b6
commit 8f401d7357
5 changed files with 61 additions and 0 deletions

View File

@@ -51,8 +51,12 @@ func (this *CreateAction) RunPost(params struct {
IsReverse bool
CondsJSON []byte
DomainsJSON []byte
Must *actions.Must
}) {
defer this.CreateLogInfo("创建路由规则:%s", params.Pattern)
params.Must.
Field("pattern", params.Pattern).
Require("请输入路径匹配规则")
@@ -85,6 +89,21 @@ func (this *CreateAction) RunPost(params struct {
params.Pattern = "/" + strings.TrimLeft(params.Pattern, "/")
}
// 域名
var domains = []string{}
if len(params.DomainsJSON) > 0 {
err := json.Unmarshal(params.DomainsJSON, &domains)
if err != nil {
this.ErrorPage(err)
return
}
// 去除可能误加的斜杠
for index, domain := range domains {
domains[index] = strings.TrimSuffix(domain, "/")
}
}
location := &serverconfigs.HTTPLocationConfig{}
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
resultPattern := location.Pattern
@@ -96,6 +115,7 @@ func (this *CreateAction) RunPost(params struct {
Pattern: resultPattern,
IsBreak: params.IsBreak,
CondsJSON: params.CondsJSON,
Domains: domains,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -31,6 +31,7 @@ func (this *IndexAction) RunGet(params struct {
this.Data["isReverse"] = locationConfig.IsReverse()
this.Data["isCaseInsensitive"] = locationConfig.IsCaseInsensitive()
this.Data["conds"] = locationConfig.Conds
this.Data["domains"] = locationConfig.Domains
this.Show()
}
@@ -50,6 +51,8 @@ func (this *IndexAction) RunPost(params struct {
CondsJSON []byte
DomainsJSON []byte
Must *actions.Must
}) {
defer this.CreateLogInfo("修改路由规则 %d 设置", params.LocationId)
@@ -86,6 +89,21 @@ func (this *IndexAction) RunPost(params struct {
}
}
// 域名
var domains = []string{}
if len(params.DomainsJSON) > 0 {
err := json.Unmarshal(params.DomainsJSON, &domains)
if err != nil {
this.ErrorPage(err)
return
}
// 去除可能误加的斜杠
for index, domain := range domains {
domains[index] = strings.TrimSuffix(domain, "/")
}
}
location := &serverconfigs.HTTPLocationConfig{}
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
resultPattern := location.Pattern
@@ -98,6 +116,7 @@ func (this *IndexAction) RunPost(params struct {
IsBreak: params.IsBreak,
IsOn: params.IsOn,
CondsJSON: params.CondsJSON,
Domains: domains,
})
if err != nil {
this.ErrorPage(err)