diff --git a/pkg/serverconfigs/domain_mismatch_action.go b/pkg/serverconfigs/domain_mismatch_action.go new file mode 100644 index 0000000..1fe02b4 --- /dev/null +++ b/pkg/serverconfigs/domain_mismatch_action.go @@ -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 +} diff --git a/pkg/serverconfigs/global_config.go b/pkg/serverconfigs/global_config.go index 3470cc4..b53ee4f 100644 --- a/pkg/serverconfigs/global_config.go +++ b/pkg/serverconfigs/global_config.go @@ -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 } diff --git a/pkg/serverconfigs/server_config.go b/pkg/serverconfigs/server_config.go index 18e0a40..491a3eb 100644 --- a/pkg/serverconfigs/server_config.go +++ b/pkg/serverconfigs/server_config.go @@ -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