39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore"
|
|
)
|
|
|
|
# API settings
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "Todo Application"
|
|
|
|
# Server settings
|
|
HOST: str = "0.0.0.0" # Listen on all available interfaces
|
|
PORT: int = 8000 # Default port
|
|
|
|
# Database settings
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
def __init__(self, **data):
|
|
super().__init__(**data)
|
|
self.DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Override settings from environment variables if they exist
|
|
if "PORT" in os.environ:
|
|
try:
|
|
self.PORT = int(os.environ["PORT"])
|
|
except ValueError:
|
|
# If PORT env var isn't a valid int, keep the default
|
|
pass
|
|
|
|
|
|
settings = Settings() |