
- Set up project structure - Create FastAPI app with SQLite database - Implement Todo API with CRUD operations - Set up Alembic for database migrations - Add health endpoint - Create README with documentation
43 lines
1.0 KiB
Python
43 lines
1.0 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.v1.api import api_router
|
|
from app.core.config import settings
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# 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=["*"],
|
|
)
|
|
|
|
# Root endpoint
|
|
@app.get("/")
|
|
def root():
|
|
"""
|
|
Root endpoint.
|
|
"""
|
|
return {"message": "Welcome to the Todo App API. Visit /docs for the API documentation."}
|
|
|
|
# Health endpoint at root level
|
|
@app.get("/health")
|
|
def health_check():
|
|
"""
|
|
Health check endpoint to verify API is running.
|
|
"""
|
|
return {"status": "ok"}
|
|
|
|
# Include API router
|
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |