Automated Action 29d75cdf08 Implement Task Management API with FastAPI and SQLite
- Set up project structure and dependencies
- Create database models and schemas for tasks
- Implement CRUD operations for tasks
- Add API endpoints for task management
- Create Alembic migrations for the database
- Add health check endpoint
- Implement error handling
- Add documentation in README.md
2025-05-17 11:20:00 +00:00

44 lines
1.2 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.api_v1.api import api_router
from app.core.config import settings
from app.core.error_handlers import add_exception_handlers
app = FastAPI(
title=settings.PROJECT_NAME,
openapi_url=f"{settings.API_V1_STR}/openapi.json",
version="0.1.0",
description="A simple task management API with FastAPI and SQLite.",
docs_url="/docs",
redoc_url="/redoc",
)
# Set all CORS enabled origins
if settings.BACKEND_CORS_ORIGINS:
app.add_middleware(
CORSMiddleware,
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Add exception handlers
add_exception_handlers(app)
# Include API router
app.include_router(api_router, prefix=settings.API_V1_STR)
# Root endpoint redirects to docs
@app.get("/", include_in_schema=False)
async def root():
"""Root endpoint redirects to docs."""
from fastapi.responses import RedirectResponse
return RedirectResponse(url="/docs")
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)