fix(HEL-564): 数据中枢入口固定内网 IP,不再按主机名推导

- 主站桌面端/移动端「数据中枢」入口固定 http://192.168.200.11:8766/admin/
  (XIAOBAI_DATAHUB_URL 仍可覆盖):域名只反代 8765,推导出的 <域名>:8766 打不开,
  同时避免数据中枢被外网摸到
- 中枢 _review_url 不再从 Host 头推导,统一取 REVIEW_PUBLIC_URL,
  默认 http://192.168.200.11:8765;compose 与 .env.example 示例值同步
- 补回归测试:Host 为域名且未配 REVIEW_PUBLIC_URL 时登录链接仍为固定内网地址
- 文档写明 Cookie 按门牌区分的边界与部署说明

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
施工员
2026-09-16 15:23:45 +08:00
co-authored by multica-agent
parent b402b3b2a8
commit a4dbe2bcf8
12 changed files with 50 additions and 27 deletions
+6 -8
View File
@@ -11,6 +11,7 @@ from urllib.parse import unquote, urlparse
from datahub.hub import Hub
from datahub.logutil import configure_logging, get_logger
from datahub.serving import ApiError, parse_query
from datahub.settings import DEFAULT_REVIEW_PUBLIC_URL
from datahub.siteauth import SITE_SESSION_COOKIE, SiteBridgeError
LOGGER = get_logger()
@@ -212,15 +213,12 @@ class HubRequestHandler(BaseHTTPRequestHandler):
def _review_url(self) -> str:
"""Browser-reachable review site URL.
In production both services sit on the same host behind different
ports, so the console derives the site URL from the Host header the
browser used; REVIEW_PUBLIC_URL overrides that when they do not.
HEL-564: fixed to REVIEW_PUBLIC_URL (default the intranet address)
instead of being derived from the browser's Host header — a domain
that only proxies 8765 would send the console back to a dead port.
"""
configured = self.hub.settings.review_public_url
if configured:
return configured.rstrip("/")
host = (self.headers.get("Host") or "").split(":")[0] or "127.0.0.1"
return f"http://{host}:8765"
configured = self.hub.settings.review_public_url or DEFAULT_REVIEW_PUBLIC_URL
return configured.rstrip("/")
def _login_url(self) -> str:
return f"{self._review_url()}/login/"
+4 -1
View File
@@ -10,6 +10,9 @@ ROOT = Path(__file__).resolve().parents[1]
DEFAULT_DB_PATH = Path(os.environ.get("DATAHUB_DB_PATH") or (ROOT / "data" / "datahub.db"))
DEFAULT_BACKUP_DIR = Path(os.environ.get("DATAHUB_BACKUP_DIR") or (ROOT / "data" / "backups"))
DEFAULT_CONFIG_PATH = ROOT / "config" / "hub-quality.config.json"
# HEL-564: 浏览器可达的主站地址固定成内网 IP,不再按请求 Host 推导——域名只
# 反代 8765,推导出来的地址在域名访问下必然打不开。
DEFAULT_REVIEW_PUBLIC_URL = "http://192.168.200.11:8765"
def _load_quality(path: Path) -> dict[str, Any]:
@@ -128,7 +131,7 @@ def load_settings(
encryption_key=str(environ.get("DATAHUB_ENCRYPTION_KEY") or "").strip(),
api_token=str(environ.get("DATAHUB_TOKEN") or "").strip(),
review_base_url=str(environ.get("REVIEW_BASE_URL") or "http://xiaobai-review:8765").strip(),
review_public_url=str(environ.get("REVIEW_PUBLIC_URL") or "").strip(),
review_public_url=str(environ.get("REVIEW_PUBLIC_URL") or DEFAULT_REVIEW_PUBLIC_URL).strip(),
hub_admin_token=str(environ.get("HUB_ADMIN_TOKEN") or "").strip(),
tushare_token=str(environ.get("TUSHARE_TOKEN") or "").strip(),
ifind_refresh_token=str(environ.get("IFIND_REFRESH_TOKEN") or "").strip(),