From 05e9dce988a9a77452cb71189af6caac097e46b8 Mon Sep 17 00:00:00 2001 From: yml Date: Sun, 15 Nov 2026 18:49:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(site):=20=E6=94=AF=E6=8C=81=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E7=A7=9F=E6=88=B7=E4=BA=8C=E7=BA=A7=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/stores/distributionSite.ts | 7 +++++-- frontend/src/stores/siteContext.spec.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/stores/distributionSite.ts b/frontend/src/stores/distributionSite.ts index 2259e6c9..f63725db 100644 --- a/frontend/src/stores/distributionSite.ts +++ b/frontend/src/stores/distributionSite.ts @@ -157,8 +157,11 @@ export function shouldProbeTenantContext( _querySite: string, _envCode: string ): boolean { - if (!hostname || hostname === 'localhost' || hostname === '127.0.0.1') return false - return !hostname.endsWith('.localhost') + const host = hostname.trim().toLowerCase() + if (!host || host === 'localhost' || host === '127.0.0.1' || host === '::1') return false + // dachui.localhost / jieyou.localhost 需要正常探测经营租户; + // 普通 localhost 和回环地址仍保留旧本地调试逻辑。 + return true } /** diff --git a/frontend/src/stores/siteContext.spec.ts b/frontend/src/stores/siteContext.spec.ts index 2030b820..3aa1282f 100644 --- a/frontend/src/stores/siteContext.spec.ts +++ b/frontend/src/stores/siteContext.spec.ts @@ -8,10 +8,13 @@ describe('shouldProbeTenantContext', () => { expect(shouldProbeTenantContext('hfb.example.com', '', '')).toBe(true) }) - it('本地开发不主动探测,避免覆盖旧分销调试模式', () => { + it('普通本地地址不探测,租户二级域名正常探测', () => { expect(shouldProbeTenantContext('localhost', '', '')).toBe(false) expect(shouldProbeTenantContext('127.0.0.1', '', '')).toBe(false) - expect(shouldProbeTenantContext('site.localhost', '', '')).toBe(false) + expect(shouldProbeTenantContext('dachui.localhost', '', '')).toBe(true) + expect(shouldProbeTenantContext('jieyou.localhost', '', '')).toBe(true) + // 非经营租户的本地子域名仍可在探测失败后回退旧分销识别。 + expect(shouldProbeTenantContext('test_1.localhost', '', '')).toBe(true) }) it('正式域名先识别经营租户,不能通过旧分站参数覆盖', () => {