Automated Action acf2757384 Fix Supervisor startup errors and improve application resilience
- Update database path configuration for better compatibility
- Add comprehensive logging system with error handling
- Create supervisord.conf with proper configuration
- Add environment variable example file
- Enhance health check endpoint to report database status
- Add detailed startup and shutdown event handlers
- Update documentation with troubleshooting information
- Update requirements with additional helpful packages
2025-06-02 22:42:07 +00:00

42 lines
1.4 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
DB_DIR = Path("app/storage/db") # Relative path for better compatibility
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR.absolute()}/db.sqlite"
# Alternative SQLite connection using memory for testing if file access is an issue
# SQLALCHEMY_DATABASE_URL: str = "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()