Automated Action a5aebe0377 Fix Supervisor startup errors and improve application resilience
- Update Supervisor configuration to use python -m uvicorn for reliable module loading
- Fix database path resolution using absolute paths
- Add in-memory SQLite database option for testing and when file access is problematic
- Improve error handling in database connection module
- Enhance logging configuration with more detailed output
- Add environment variables and documentation for better configuration options
- Update troubleshooting guide with common issues and solutions
2025-06-02 22:47:33 +00:00

44 lines
1.6 KiB
Python

import os
from pathlib import Path
from typing import List
from pydantic import AnyHttpUrl, validator
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=True,
)
PROJECT_NAME: str = "Blogging API"
API_V1_STR: str = "/api/v1"
# JWT token settings
SECRET_KEY: str = os.getenv("SECRET_KEY", "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7")
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 8 days
# SQLite settings
# Main database location - use absolute path for reliability
DB_DIR = Path(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) / "app" / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
# Fallback to in-memory SQLite if file access fails
USE_IN_MEMORY_DB: bool = os.getenv("USE_IN_MEMORY_DB", "").lower() in ("true", "1", "yes")
if USE_IN_MEMORY_DB:
SQLALCHEMY_DATABASE_URL = "sqlite://" # In-memory SQLite database
# CORS settings
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(cls, v: str | List[str]) -> 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)
settings = Settings()