fix(site): 支持本地租户二级域名识别
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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('正式域名先识别经营租户,不能通过旧分站参数覆盖', () => {
|
||||
|
||||
Reference in New Issue
Block a user