58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import secrets
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Optional, Union
|
|
|
|
from pydantic import AnyHttpUrl, field_validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
import os
|
|
|
|
# Use a simple, universally accessible path for database
|
|
# First try environment variable, then local directory
|
|
DB_PATH = os.environ.get("DB_PATH")
|
|
if DB_PATH:
|
|
DB_DIR = Path(DB_PATH)
|
|
print(f"Using database path from environment: {DB_DIR}")
|
|
else:
|
|
# Use 'db' directory in the current working directory
|
|
DB_DIR = Path.cwd() / "db"
|
|
print(f"Using local database path: {DB_DIR}")
|
|
|
|
# Create database directory
|
|
try:
|
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
print(f"Created or verified database directory: {DB_DIR}")
|
|
except Exception as e:
|
|
print(f"Error creating database directory: {e}")
|
|
# Fall back to /tmp if we can't create our preferred directory
|
|
DB_DIR = Path("/tmp")
|
|
print(f"Falling back to temporary directory: {DB_DIR}")
|
|
|
|
class Settings(BaseSettings):
|
|
PROJECT_NAME: str = "Task Manager API"
|
|
# No API version prefix - use direct paths
|
|
API_PREFIX: str = ""
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
|
# 60 minutes * 24 hours * 8 days = 8 days
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
|
|
|
# CORS Configuration
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@field_validator("BACKEND_CORS_ORIGINS", mode="before")
|
|
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 configuration
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
model_config = {
|
|
"case_sensitive": True
|
|
}
|
|
|
|
|
|
settings = Settings() |