fastapi-demo/main.py

23 lines
626 B
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.

"""
FastAPI 应用主入口
"""
from app.core.application import create_application
from app.core.config import settings
# 创建应用实例
app = create_application()
if __name__ == "__main__":
import uvicorn
# 根据环境决定是否使用字符串形式的 app支持热重载
app_str = "main:app" if settings.RELOAD else app
uvicorn.run(
app_str,
host=settings.HOST,
port=settings.PORT,
reload=settings.RELOAD,
log_level=settings.LOG_LEVEL.lower(),
workers=1 if settings.RELOAD else settings.WORKERS, # 热重载模式下只能用1个worker
)