mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-07 15:20:24 +08:00
找不到匹配的域名时可以指定默认域名、指定不匹配时的处理动作
This commit is contained in:
25
pkg/serverconfigs/domain_mismatch_action.go
Normal file
25
pkg/serverconfigs/domain_mismatch_action.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package serverconfigs
|
||||
|
||||
import "github.com/iwind/TeaGo/maps"
|
||||
|
||||
const (
|
||||
DomainMismatchActionPage = "page"
|
||||
DomainMismatchActionClose = "close"
|
||||
)
|
||||
|
||||
type DomainMismatchPageOptions struct {
|
||||
StatusCode int `yaml:"statusCode" json:"statusCode"`
|
||||
ContentHTML string `yaml:"contentHTML" json:"contentHTML"`
|
||||
}
|
||||
|
||||
type DomainMismatchCloseOptions struct {
|
||||
}
|
||||
|
||||
type DomainMismatchAction struct {
|
||||
Code string `yaml:"code" json:"code"` // 动作代号
|
||||
Options maps.Map `yaml:"options" json:"options"` // 动作选项
|
||||
}
|
||||
|
||||
func (this *DomainMismatchAction) Init() error {
|
||||
return nil
|
||||
}
|
||||
@@ -4,7 +4,10 @@ package serverconfigs
|
||||
type GlobalConfig struct {
|
||||
// HTTP & HTTPS相关配置
|
||||
HTTPAll struct {
|
||||
MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名
|
||||
MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名
|
||||
AllowMismatchDomains []string `yaml:"allowMismatchDomains" json:"allowMismatchDomains"` // 允许的不匹配的域名
|
||||
DefaultDomain string `yaml:"defaultDomain" json:"defaultDomain"` // 默认的域名
|
||||
DomainMismatchAction *DomainMismatchAction `yaml:"domainMismatchAction" json:"domainMismatchAction"` // 不匹配时采取的动作
|
||||
} `yaml:"httpAll" json:"httpAll"`
|
||||
|
||||
HTTP struct{} `yaml:"http" json:"http"`
|
||||
@@ -22,5 +25,12 @@ type GlobalConfig struct {
|
||||
}
|
||||
|
||||
func (this *GlobalConfig) Init() error {
|
||||
// HTTPAll
|
||||
if this.HTTPAll.DomainMismatchAction != nil {
|
||||
err := this.HTTPAll.DomainMismatchAction.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -195,6 +195,11 @@ func (this *ServerConfig) MatchName(name string) bool {
|
||||
|
||||
// 判断是否严格匹配
|
||||
func (this *ServerConfig) MatchNameStrictly(name string) bool {
|
||||
for _, serverName := range this.AliasServerNames {
|
||||
if serverName == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, serverName := range this.ServerNames {
|
||||
if serverName.Name == name {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user