
- Add app/db/base.py with SQLAlchemy Base class - Add app/db/session.py with SQLite database connection using absolute path - Add app/models/todo.py with Todo model including all required fields - Add empty __init__.py files for proper package structure
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
from app.api.v1.api import api_router
|
|
from app.core.config import settings
|
|
|
|
# Create FastAPI app instance
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
description="A simple Todo API built with FastAPI",
|
|
version="1.0.0",
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# Add CORS middleware to allow all origins
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # Allow all origins
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include API router
|
|
app.include_router(api_router, prefix="/api/v1")
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""
|
|
Root endpoint that returns basic app information.
|
|
"""
|
|
return JSONResponse(
|
|
content={
|
|
"title": settings.PROJECT_NAME,
|
|
"description": "A simple Todo API built with FastAPI",
|
|
"version": "1.0.0",
|
|
"documentation": "/docs",
|
|
"health_check": "/health"
|
|
}
|
|
)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
"""
|
|
Health check endpoint to report application status.
|
|
"""
|
|
return JSONResponse(
|
|
content={
|
|
"status": "healthy",
|
|
"service": settings.PROJECT_NAME,
|
|
"version": "1.0.0"
|
|
}
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(
|
|
"main:app",
|
|
host="0.0.0.0",
|
|
port=8000,
|
|
reload=True
|
|
) |