/** * 分销(分站)管理后台入口地址。 * * 解析优先级: * 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` : '' }