Automated Action a2ba7e0a54 Fix port binding issue with dynamic port selection
Added port conflict resolution to handle cases where port 8001 is already in use.
The app now checks if a port is available and incrementally tries higher ports
until it finds one that's free.

generated with BackendIM... (backend.im)
2025-05-14 01:26:28 +00:00

30 lines
963 B
Python

from typing import List, Optional, Union, ClassVar
from pathlib import Path
from pydantic import AnyHttpUrl, validator
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
PROJECT_NAME: str = "Quick REST API Service"
PORT: int = 8001
# CORS settings
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, (list, str)):
return v
raise ValueError(v)
# Database settings
DB_DIR: ClassVar[Path] = Path("/app/storage/db")
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
class Config:
case_sensitive = True
settings = Settings()