diff --git a/.gitignore b/.gitignore index 0389270..519c552 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ Thumbs.db !.env.example *.pem *.key +ssl/ # ============ Backend (Python) ============ # 字节码 / 缓存 diff --git a/backend/app/main.py b/backend/app/main.py index 3398471..aa49f15 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -11,6 +11,9 @@ from app.db import SessionLocal, init_db from app.services.user_service import ensure_default_admin FRONTEND_DIST = Path(__file__).resolve().parent.parent / "dist" +SSL_DIR = Path(__file__).resolve().parent.parent.parent / "ssl" +SSL_CERT_FILE = SSL_DIR / "finai.ctc-zc.com.pem" +SSL_KEY_FILE = SSL_DIR / "finai.ctc-zc.com.key" def create_app() -> FastAPI: @@ -69,3 +72,22 @@ def _mount_frontend(app: FastAPI) -> None: app = create_app() + + +if __name__ == "__main__": + import uvicorn + + ssl_kwargs: dict = {} + if SSL_CERT_FILE.is_file() and SSL_KEY_FILE.is_file(): + ssl_kwargs = { + "ssl_certfile": str(SSL_CERT_FILE), + "ssl_keyfile": str(SSL_KEY_FILE), + } + + uvicorn.run( + "app.main:app", + host="0.0.0.0", + port=8775, + reload=True, + **ssl_kwargs, + ) diff --git a/backend/run.bat b/backend/run.bat index 04de8f3..545e9c5 100644 --- a/backend/run.bat +++ b/backend/run.bat @@ -1,4 +1,4 @@ -@echo off +@echo off chcp 65001 >nul setlocal @@ -12,8 +12,8 @@ if not exist ".venv\Scripts\python.exe" ( ".venv\Scripts\python.exe" -m pip install fastapi "uvicorn[standard]" sqlalchemy "psycopg[binary]" pydantic-settings "python-jose[cryptography]" "passlib[bcrypt]" python-multipart httpx tencentcloud-sdk-python-lke || goto :error ) -echo [backend] 启动 uvicorn app.main:app http://127.0.0.1:8775 -".venv\Scripts\python.exe" -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8775 +echo [backend] 启动 uvicorn app.main:app https://0.0.0.0:8775 (SSL) +".venv\Scripts\python.exe" -m app.main goto :end :error @@ -23,4 +23,4 @@ exit /b 1 :end endlocal -pause +pause \ No newline at end of file