mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
fixed homepage not respecting homepage.show field, disabled schema validation for included file
This commit is contained in:
parent
6211ddcdf0
commit
e566fd9b57
6 changed files with 33 additions and 15 deletions
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
NoSchemaValidation = GetEnvBool("GOPROXY_NO_SCHEMA_VALIDATION", false)
|
||||
NoSchemaValidation = GetEnvBool("GOPROXY_NO_SCHEMA_VALIDATION", true)
|
||||
IsTest = GetEnvBool("GOPROXY_TEST", false) || strings.HasSuffix(os.Args[0], ".test")
|
||||
IsDebug = GetEnvBool("GOPROXY_DEBUG", IsTest)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
H "github.com/yusing/go-proxy/internal/homepage"
|
||||
M "github.com/yusing/go-proxy/internal/models"
|
||||
|
@ -48,10 +49,18 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig {
|
|||
}
|
||||
|
||||
entry := r.Entry()
|
||||
if entry.Homepage == nil {
|
||||
entry.Homepage = &H.HomePageItem{
|
||||
Show: r.Entry().IsExplicit || !p.IsExplicitOnly(),
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("%s isexplicit: %v, explicitonly: %v", r, r.Entry().IsExplicit, p.IsExplicitOnly())
|
||||
|
||||
item := entry.Homepage
|
||||
|
||||
if !item.Initialized {
|
||||
item.Show = r.Entry().IsExplicit || !p.IsExplicitOnly()
|
||||
if !item.Show && !item.IsEmpty() {
|
||||
item.Show = true
|
||||
}
|
||||
|
||||
if !item.Show || r.Type() != R.RouteTypeReverseProxy {
|
||||
|
@ -86,7 +95,7 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig {
|
|||
}
|
||||
item.AltURL = r.URL().String()
|
||||
|
||||
hpCfg.Add(&item)
|
||||
hpCfg.Add(item)
|
||||
})
|
||||
return hpCfg
|
||||
}
|
||||
|
|
|
@ -58,7 +58,14 @@ func ApplyLabel[T any](obj *T, l *Label) E.NestedError {
|
|||
}
|
||||
dst, ok := field.Interface().(NestedLabelMap)
|
||||
if !ok {
|
||||
return U.Deserialize(U.SerializedObject{nestedLabel.Namespace: nestedLabel.Value}, field.Addr().Interface())
|
||||
if field.Kind() == reflect.Ptr {
|
||||
if field.IsNil() {
|
||||
field.Set(reflect.New(field.Type().Elem()))
|
||||
}
|
||||
} else {
|
||||
field = field.Addr()
|
||||
}
|
||||
return U.Deserialize(U.SerializedObject{nestedLabel.Namespace: nestedLabel.Value}, field.Interface())
|
||||
}
|
||||
if dst == nil {
|
||||
field.Set(reflect.MakeMap(reflect.TypeFor[NestedLabelMap]()))
|
||||
|
|
|
@ -13,12 +13,20 @@ type (
|
|||
Description string `yaml:"description" json:"description"`
|
||||
WidgetConfig map[string]any `yaml:",flow" json:"widget_config"`
|
||||
|
||||
SourceType string `yaml:"-" json:"source_type"`
|
||||
Initialized bool `yaml:"-" json:"-"`
|
||||
AltURL string `yaml:"-" json:"alt_url"` // original proxy target
|
||||
SourceType string `yaml:"-" json:"source_type"`
|
||||
AltURL string `yaml:"-" json:"alt_url"` // original proxy target
|
||||
}
|
||||
)
|
||||
|
||||
func (item *HomePageItem) IsEmpty() bool {
|
||||
return item == nil || (item.Name == "" &&
|
||||
item.Icon == "" &&
|
||||
item.URL == "" &&
|
||||
item.Category == "" &&
|
||||
item.Description == "" &&
|
||||
len(item.WidgetConfig) == 0)
|
||||
}
|
||||
|
||||
func NewHomePageConfig() HomePageConfig {
|
||||
return HomePageConfig(make(map[string]HomePageCategory))
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ type (
|
|||
NoTLSVerify bool `yaml:"no_tls_verify" json:"no_tls_verify,omitempty"` // https proxy only
|
||||
PathPatterns []string `yaml:"path_patterns" json:"path_patterns,omitempty"` // http(s) proxy only
|
||||
Middlewares D.NestedLabelMap `yaml:"middlewares" json:"middlewares,omitempty"`
|
||||
Homepage H.HomePageItem `yaml:"homepage" json:"homepage"`
|
||||
Homepage *H.HomePageItem `yaml:"homepage" json:"homepage"`
|
||||
|
||||
/* Docker only */
|
||||
*D.ProxyProperties `yaml:"-" json:"proxy_properties"`
|
||||
|
|
|
@ -79,12 +79,6 @@ func (p *FileProvider) LoadRoutesImpl() (routes R.Routes, res E.NestedError) {
|
|||
return
|
||||
}
|
||||
|
||||
if !common.NoSchemaValidation {
|
||||
if err = Validate(data); err.HasError() {
|
||||
b.Add(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = entries.UnmarshalFromYAML(data); err.HasError() {
|
||||
b.Add(err)
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue