refactor: Web 服务器从 gunicorn 迁移到 uvicorn
This commit is contained in:
@@ -8,6 +8,23 @@ from pydantic import BaseModel, Field, computed_field, field_validator, model_va
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
def _resolve_project_root() -> Path:
|
||||
current = Path(__file__).resolve()
|
||||
for parent in current.parents:
|
||||
if (
|
||||
(parent / "pyproject.toml").is_file()
|
||||
and (parent / "backend").is_dir()
|
||||
and (parent / "infra").is_dir()
|
||||
):
|
||||
return parent
|
||||
|
||||
for parent in current.parents:
|
||||
if parent.name == "backend":
|
||||
return parent.parent
|
||||
|
||||
return Path.cwd().resolve()
|
||||
|
||||
|
||||
class RuntimeSettings(BaseModel):
|
||||
environment: Literal["dev", "test", "prod"] = "dev"
|
||||
service_name: str = "app"
|
||||
@@ -171,6 +188,9 @@ def _resolve_env_file() -> str:
|
||||
return ".env"
|
||||
|
||||
|
||||
PROJECT_ROOT = _resolve_project_root()
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
runtime: RuntimeSettings = RuntimeSettings()
|
||||
cors: CorsSettings = CorsSettings()
|
||||
|
||||
Reference in New Issue
Block a user