2025-05-17 03:24:28 +00:00

41 lines
1.1 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.health import router as health_router
from app.api.v1.api import api_router
from app.core.config import API_V1_STR, PROJECT_NAME
from app.db.session import Base, engine
# Create tables if they don't exist
Base.metadata.create_all(bind=engine)
app = FastAPI(
title=PROJECT_NAME,
description="A simple Todo API built with FastAPI and SQLite",
version="0.1.0",
docs_url="/docs",
redoc_url="/redoc",
)
# Set all CORS enabled origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins in development
allow_credentials=True,
allow_methods=["*"], # Allow all methods
allow_headers=["*"], # Allow all headers
)
# Include routers
app.include_router(api_router, prefix=API_V1_STR)
app.include_router(health_router)
@app.get("/")
def root():
"""
Root endpoint that redirects to the API documentation.
"""
return {
"message": "Welcome to the Todo API! Visit /docs for the API documentation."
}