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:
@@ -75,6 +75,60 @@ func TestBootstrapDomainsIsIdempotentAndRejectsHostConflict(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBootstrapDomainsRegistersShowDomainAsDachuiShowcase(t *testing.T) {
|
||||
repo, _, _ := setupTenantRepoTest(t)
|
||||
cfg := BootstrapConfig{
|
||||
PrimaryDomain: "hao858.com",
|
||||
JieyouDomain: "zuhaox.com",
|
||||
// CADDY_SHOW_DOMAIN 按约定只填域名(不带协议);重复启动必须幂等。
|
||||
ShowDomain: "xh.hao858.com",
|
||||
}
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := BootstrapDomains(t.Context(), repo.db, cfg); err != nil {
|
||||
t.Fatalf("bootstrap domains run %d: %v", i+1, err)
|
||||
}
|
||||
}
|
||||
|
||||
repo.Invalidate()
|
||||
scope, err := repo.ResolveHost(t.Context(), "xh.hao858.com")
|
||||
if err != nil {
|
||||
t.Fatalf("resolve show host: %v", err)
|
||||
}
|
||||
if scope == nil || scope.TenantCode != "dachui" || scope.DomainType != "showcase" {
|
||||
t.Fatalf("show scope = %#v, want dachui/showcase", scope)
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := repo.db.Model(&model.TenantDomain{}).Count(&count).Error; err != nil {
|
||||
t.Fatalf("count domains: %v", err)
|
||||
}
|
||||
if count != 4 {
|
||||
t.Fatalf("domain count = %d, want 4", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBootstrapDomainsKeepsRegisteredTypeWhenShowDomainOverlaps(t *testing.T) {
|
||||
repo, _, _ := setupTenantRepoTest(t)
|
||||
cfg := BootstrapConfig{
|
||||
PrimaryDomain: "hao858.com",
|
||||
JieyouDomain: "zuhaox.com",
|
||||
// 误把选号网配成解忧域名时,不能让解忧的 storefront 被改写成 dachui/showcase。
|
||||
ShowDomain: "zuhaox.com",
|
||||
}
|
||||
if err := BootstrapDomains(t.Context(), repo.db, cfg); err != nil {
|
||||
t.Fatalf("bootstrap domains: %v", err)
|
||||
}
|
||||
|
||||
repo.Invalidate()
|
||||
scope, err := repo.ResolveHost(t.Context(), "zuhaox.com")
|
||||
if err != nil {
|
||||
t.Fatalf("resolve jieyou host: %v", err)
|
||||
}
|
||||
if scope == nil || scope.TenantCode != "jieyou" || scope.DomainType != "storefront" {
|
||||
t.Fatalf("jieyou scope = %#v, want jieyou/storefront", scope)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveCode(t *testing.T) {
|
||||
repo, dachui, _ := setupTenantRepoTest(t)
|
||||
scope, err := repo.ResolveCode(t.Context(), " DAC HUI ")
|
||||
|
||||
Reference in New Issue
Block a user