mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 23:54:21 +08:00
- --no-ui:不托管 Web UI 前端(根路径 404),仅 /api/v1/* REST 接口, 且不自动打开浏览器——给 AI Agent / 程序化调用省去前端资源 - create_app/_create_app 新增 enable_ui 参数(默认 True 行为不变) - 测试锁定:no-ui 模式无 web-ui Mount 且 API 路由完整;四道门禁全绿 (ruff / ruff format / mypy / 1079 tests),实测根路径 404 + API 正常
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
"""easy-tdx Web API — FastAPI REST + WebSocket layer.
|
|
|
|
Install with: pip install easy-tdx[web]
|
|
|
|
Usage::
|
|
|
|
from easy_tdx.web import create_app
|
|
|
|
app = create_app()
|
|
|
|
# Run with uvicorn:
|
|
# uvicorn easy_tdx.web:app --host 0.0.0.0 --port 8000
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from fastapi import FastAPI
|
|
|
|
|
|
def create_app(
|
|
host: str | None = None,
|
|
port: int | None = None,
|
|
timeout: float | None = None,
|
|
*,
|
|
enable_ui: bool = True,
|
|
) -> FastAPI:
|
|
"""Create and configure the FastAPI application.
|
|
|
|
Args:
|
|
host: TDX server host (None = auto-detect best host).
|
|
port: TDX server port (None = default 7709).
|
|
timeout: Connection timeout in seconds.
|
|
enable_ui: False 时不托管 Web UI 前端(纯 API 模式,serve --no-ui)。
|
|
|
|
Returns:
|
|
Configured FastAPI application instance.
|
|
"""
|
|
from easy_tdx.web.app import _create_app
|
|
|
|
return _create_app(host=host, port=port, timeout=timeout, enable_ui=enable_ui)
|
|
|
|
|
|
def app_factory() -> FastAPI:
|
|
"""Factory function for uvicorn --reload mode."""
|
|
from easy_tdx.web.app import _create_app
|
|
|
|
return _create_app()
|
|
|
|
|
|
__all__ = ["create_app", "app_factory"]
|