34 lines
856 B
Python
34 lines
856 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from app.routers import todo, health
|
|
from app.database import engine, Base
|
|
|
|
# Create the database tables
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
Base.metadata.create_all(bind=engine)
|
|
yield
|
|
|
|
# Initialize FastAPI app
|
|
app = FastAPI(
|
|
title="Simple Todo API",
|
|
description="A simple Todo API built with FastAPI and SQLite",
|
|
version="0.1.0",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
# Add CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # For development, in production specify the allowed origins
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(health.router)
|
|
app.include_router(todo.router) |