File size: 2,153 Bytes
1941764 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
# Create FastAPI application
app = FastAPI(
title="Todo Application API",
description="Backend API for Todo application with JWT authentication",
version="1.0.0",
)
# CORS Configuration
CORS_ORIGINS = os.getenv("CORS_ORIGINS", "http://localhost:3000,http://localhost:3001,http://localhost:3002,http://localhost:3003,http://localhost:3004,http://localhost:3005").split(",")
# Configure CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=CORS_ORIGINS,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
allow_headers=["*"],
expose_headers=["*"],
max_age=3600,
)
# Initialize database tables on startup
from src.database import create_db_and_tables
@app.on_event("startup")
def on_startup():
"""Initialize database tables on application startup."""
try:
create_db_and_tables()
except Exception as e:
print(f"Warning: Could not initialize database tables: {e}")
# Continue anyway - tables might already exist
# Health check endpoint
@app.get("/health")
async def health_check():
"""Health check endpoint to verify API is running."""
return {"status": "healthy"}
# Root endpoint
@app.get("/")
async def root():
"""Root endpoint with API information."""
return {
"message": "Todo Application API",
"version": "1.0.0",
"docs": "/docs",
"health": "/health"
}
# Router registration
from src.api import auth, tasks, subtasks, password_reset
# AI router temporarily disabled due to Vercel size constraints
# from src.api import ai
app.include_router(auth.router, prefix="/api/auth", tags=["Authentication"])
app.include_router(password_reset.router, prefix="/api/auth", tags=["Password Reset"])
app.include_router(tasks.router, prefix="/api/tasks", tags=["Tasks"])
app.include_router(subtasks.router, prefix="/api", tags=["Subtasks"])
# app.include_router(ai.router, prefix="/api/ai", tags=["AI Features"])
|