
- Set up project structure and dependencies - Create Todo model with SQLAlchemy - Implement CRUD operations for todos - Create API endpoints for todos - Set up Alembic migrations - Update documentation generated with BackendIM... (backend.im)
36 lines
773 B
Python
36 lines
773 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from pathlib import Path
|
|
|
|
from app.api import api_router
|
|
from app.db.session import create_db_and_tables
|
|
|
|
app = FastAPI(
|
|
title="Simple Todo API",
|
|
description="A simple Todo API",
|
|
version="0.1.0",
|
|
)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(api_router)
|
|
|
|
@app.get("/health", tags=["Health"])
|
|
async def health():
|
|
return {"status": "ok"}
|
|
|
|
@app.on_event("startup")
|
|
def on_startup():
|
|
create_db_and_tables()
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) |