feat(tenant): 选号网域名随部署自动登记为 dachui 租户域名

选号网 hfb_show 与主站共用后端,生产环境的 Unknown Host 保护会把未登记的 xh.hao858.com 以 site_not_found 拒绝,导致列表接口 404。

后端启动时读取 CADDY_SHOW_DOMAIN,把选号网域名登记为 dachui 的 showcase 租户域名;与主站/解忧域名重合时保留原类型。避免换库或重建后依赖人工补 SQL。
This commit is contained in:
yml
2026-11-24 12:58:04 +08:00
parent 44f883866c
commit b63f5d771b
6 changed files with 83 additions and 2 deletions
+16
View File
@@ -148,6 +148,9 @@ func (r *Repository) cacheHost(host string, scope *Scope) {
type BootstrapConfig struct {
PrimaryDomain string
JieyouDomain string
// ShowDomain 是选号网(hfb_show)域名,登记为 dachui 的 showcase 域名。
// 选号网与主站共用后端,未登记时 RequireKnownApplicationHost 会拒绝其 /api 请求。
ShowDomain string
}
func BootstrapDomains(ctx context.Context, db *gorm.DB, cfg BootstrapConfig) error {
@@ -158,19 +161,32 @@ func BootstrapDomains(ctx context.Context, db *gorm.DB, cfg BootstrapConfig) err
primary := sitecode.ExtractHost(cfg.PrimaryDomain)
jieyou := sitecode.ExtractHost(cfg.JieyouDomain)
registered := make(map[string]struct{}, 4)
if primary != "" {
if err := repo.UpsertDomain(ctx, "dachui", primary, "storefront"); err != nil {
return err
}
registered[primary] = struct{}{}
h5 := "h5." + primary
if err := repo.UpsertDomain(ctx, "dachui", h5, "storefront_alias"); err != nil {
return err
}
registered[h5] = struct{}{}
}
if jieyou != "" && jieyou != primary {
if err := repo.UpsertDomain(ctx, "jieyou", jieyou, "storefront"); err != nil {
return err
}
registered[jieyou] = struct{}{}
}
// 选号网域名单独登记为 dachui 的 showcase;与已登记域名重合时保留原类型,
// 避免把主站 storefront 或解忧域名改写成 showcase。
if show := sitecode.ExtractHost(cfg.ShowDomain); show != "" {
if _, ok := registered[show]; !ok {
if err := repo.UpsertDomain(ctx, "dachui", show, "showcase"); err != nil {
return err
}
}
}
return nil
}