huoyan-enterprise/backend/main.py

34 lines
1.1 KiB
Python
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.

"""
后端 ASGI 入口(位于 backend 根目录,便于短命令启动)。
端口说明
--------
- 直接用 **Uvicorn 命令行** 时,**不会**读 ``.env`` 里的 ``API_PORT``;未写 ``--port`` 时 **默认为 8000**。
- 若希望与配置一致(``API_HOST`` / ``API_PORT``,来自 ``.env``),请二选一:
1. 显式传参:``uv run uvicorn main:app --reload --host 0.0.0.0 --port 7862``
2. 使用模块方式启动(推荐,自动使用配置中的端口)::
uv run python -m main
等价写法(手动指定,默认端口见代码 ``core.config.Settings.api_port``,一般为 7861::
uv run uvicorn main:app --reload --host 0.0.0.0 --port 7861
"""
from core.main import app
__all__ = ["app"]
if __name__ == "__main__":
import uvicorn
from core.config import settings
# 须使用 ``python -m main``(在 backend 目录下),这样 ``main:app`` 才能被正确 importreload 依赖字符串引用
uvicorn.run(
"main:app",
host=settings.api_host,
port=settings.api_port,
reload=True,
)