mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-30 07:56:21 +08:00
fix(cli): preserve public host in local API proxy
This commit is contained in:
@@ -300,6 +300,8 @@ LOCAL_FRONTEND_SERVICE_SCRIPT = textwrap.dedent(
|
||||
app.use(
|
||||
'/api',
|
||||
proxy(`${backendHost}:${backendPort}`, {
|
||||
// 保留设备访问的主机名,避免播放清单生成后端回环地址。
|
||||
preserveHostHdr: true,
|
||||
proxyReqPathResolver: req => `/api${req.url}`
|
||||
})
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import re
|
||||
import tempfile
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
@@ -27,6 +28,24 @@ def load_local_setup_module():
|
||||
return module
|
||||
|
||||
|
||||
def test_frontend_service_preserves_public_api_host(tmp_path):
|
||||
"""
|
||||
生成的 API 代理保留外部 Host,供播放清单生成设备可达的媒体地址。
|
||||
"""
|
||||
module = load_local_setup_module()
|
||||
module._write_local_frontend_service_script(tmp_path)
|
||||
script = (tmp_path / "service.js").read_text(encoding="utf-8")
|
||||
api_proxy = re.search(
|
||||
r"app\.use\(\s*'/api',\s*proxy\([^,]+,\s*\{(?P<options>.*?)\}\)",
|
||||
script,
|
||||
re.DOTALL,
|
||||
)
|
||||
|
||||
assert api_proxy is not None
|
||||
assert "preserveHostHdr: true" in api_proxy["options"]
|
||||
assert "proxyReqPathResolver: req => `/api${req.url}`" in api_proxy["options"]
|
||||
|
||||
|
||||
def test_repo_frontend_version_reads_version_file():
|
||||
"""
|
||||
前端固定版本取自当前源码声明。
|
||||
|
||||
Reference in New Issue
Block a user