Reworked variable system, no longer hardcoded
This commit is contained in:
14
backend/.env.example
Normal file
14
backend/.env.example
Normal file
@@ -0,0 +1,14 @@
|
||||
# Database Configuration
|
||||
DATABASE_URL=sqlite:///./tesseract.db
|
||||
|
||||
# API Configuration
|
||||
API_TITLE=Tesseract - Nested Todo Tree API
|
||||
API_DESCRIPTION=API for managing deeply nested todo trees
|
||||
API_VERSION=1.0.0
|
||||
|
||||
# CORS Configuration (comma-separated list of allowed origins)
|
||||
CORS_ORIGINS=http://localhost:5173,http://localhost:3000
|
||||
|
||||
# Server Configuration
|
||||
HOST=0.0.0.0
|
||||
PORT=8000
|
||||
@@ -1,8 +1,9 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from .settings import settings
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./tesseract.db"
|
||||
SQLALCHEMY_DATABASE_URL = settings.database_url
|
||||
|
||||
engine = create_engine(
|
||||
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
|
||||
|
||||
@@ -6,20 +6,21 @@ import json
|
||||
|
||||
from . import models, schemas, crud
|
||||
from .database import engine, get_db
|
||||
from .settings import settings
|
||||
|
||||
# Create database tables
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI(
|
||||
title="Tesseract - Nested Todo Tree API",
|
||||
description="API for managing deeply nested todo trees",
|
||||
version="1.0.0"
|
||||
title=settings.api_title,
|
||||
description=settings.api_description,
|
||||
version=settings.api_version
|
||||
)
|
||||
|
||||
# CORS middleware for frontend
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:5173", "http://localhost:3000"], # Vite default port
|
||||
allow_origins=settings.cors_origins_list,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
|
||||
37
backend/app/settings.py
Normal file
37
backend/app/settings.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from typing import List
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings loaded from environment variables"""
|
||||
|
||||
# Database Configuration
|
||||
database_url: str = "sqlite:///./tesseract.db"
|
||||
|
||||
# API Configuration
|
||||
api_title: str = "Tesseract - Nested Todo Tree API"
|
||||
api_description: str = "API for managing deeply nested todo trees"
|
||||
api_version: str = "1.0.0"
|
||||
|
||||
# CORS Configuration
|
||||
cors_origins: str = "http://localhost:5173,http://localhost:3000"
|
||||
|
||||
# Server Configuration
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
case_sensitive=False,
|
||||
extra="ignore"
|
||||
)
|
||||
|
||||
@property
|
||||
def cors_origins_list(self) -> List[str]:
|
||||
"""Parse comma-separated CORS origins into a list"""
|
||||
return [origin.strip() for origin in self.cors_origins.split(",")]
|
||||
|
||||
|
||||
# Global settings instance
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user