Files
hfb_sys/frontend/src/shared/utils/distributionAdmin.ts
T
yml2213 64a4e5bb16 fix(distribution): 修正分销后台入口地址并收口主站后台隐藏路径
- 新增前端 distributionAdmin 工具:优先 VITE_DISTRIBUTION_ADMIN_URL,
  本地开发回退 5190,生产按 distribution.<主站域名> 推导
- 替换主站后台「打开独立分销后台」按钮与开通凭证中硬编码的 :5190
- 分销后台复制凭证改用 window.location.origin,去掉硬编码 http
- Caddyfile 中 /manage-7x9k2p 仅主站域名放行,分站域名统一 404
- 构建/部署链路透传 VITE_DISTRIBUTION_ADMIN_URL 与 ADMIN_BASE_PATH
2026-09-16 15:09:38 +08:00

36 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 分销(分站)管理后台入口地址。
*
* 解析优先级:
* 1. 构建期注入的 VITE_DISTRIBUTION_ADMIN_URL
* (deploy/docker-compose.prod.yml 会把它透传给 Caddy 镜像构建,推荐生产显式配置);
* 2. 本地开发保留独立端口(与 scripts/dev.sh 的 DEV_DISTRIBUTION_PORT 默认值一致);
* 3. 其余情况按 deploy/caddy/Caddyfile 的 `distribution.{$CADDY_DOMAIN}` 规则从当前主站域名推导,
* 主站可能同时挂 h5.{$CADDY_DOMAIN} 过渡域名,推导时先去掉 h5. 前缀。
*/
const DEV_DISTRIBUTION_ADMIN_PORT = 5190
function isLocalHostname(hostname: string): boolean {
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname.endsWith('.localhost')
}
export function distributionAdminBaseUrl(): string {
const configured = (import.meta.env.VITE_DISTRIBUTION_ADMIN_URL as string | undefined)?.trim()
if (configured) return configured.replace(/\/+$/, '')
if (typeof window === 'undefined') return ''
const { hostname, protocol } = window.location
if (isLocalHostname(hostname)) {
return `http://${hostname}:${DEV_DISTRIBUTION_ADMIN_PORT}`
}
const rootHostname = hostname.startsWith('h5.') ? hostname.slice('h5.'.length) : hostname
return `${protocol}//distribution.${rootHostname}`
}
export function distributionAdminLoginUrl(): string {
const base = distributionAdminBaseUrl()
return base ? `${base}/login` : ''
}