File size: 1,332 Bytes
6bed18e 7e92771 6bed18e 7e92771 6bed18e 7e92771 6bed18e 8e555de 6bed18e a5a4b50 7e92771 a5a4b50 6bed18e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | from fastapi import FastAPI
from src.api.v1 import tasks
from src.api.v1.auth import router as auth_router
from src.auth.middleware import JWTMiddleware
from fastapi.middleware.cors import CORSMiddleware
from src.core.database import create_db_and_tables
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
create_db_and_tables()
yield
# Shutdown (if needed)
app = FastAPI(title="Todo API", version="1.0.0", lifespan=lifespan)
# Add JWT authentication middleware
app.add_middleware(JWTMiddleware)
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:3000",
"https://ahmed-hackathon-ii-phase-ii.vercel.app",
], # frontend
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include API routes
app.include_router(tasks.router, prefix="/api/v1/tasks", tags=["tasks"])
app.include_router(auth_router, prefix="/api/v1", tags=["auth"])
# Also include routes at root level for backward compatibility
app.include_router(auth_router, tags=["auth-root"])
app.include_router(tasks.router, prefix="/tasks", tags=["tasks-root"])
@app.get("/")
def read_root():
return {"Hello": "World"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)
|