34 lines
899 B
Python
34 lines
899 B
Python
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from api.routers import health_router, todo_router
|
|
from db.database import create_tables
|
|
|
|
app = FastAPI(
|
|
title="SimpleTodoApp API",
|
|
description="API for a simple todo application",
|
|
version="0.1.0",
|
|
)
|
|
|
|
# CORS settings
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # For development, in production specify your frontend domain
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(todo_router.router, prefix="/api/todos", tags=["todos"])
|
|
app.include_router(health_router.router, prefix="/api", tags=["health"])
|
|
|
|
# Create database tables on startup
|
|
@app.on_event("startup")
|
|
async def startup():
|
|
create_tables()
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|