Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from .database import engine | |
| from .models import user, task # Import models to register them with SQLModel | |
| def create_app(): | |
| app = FastAPI( | |
| title="Task Management API", | |
| description="API for managing tasks with user authentication", | |
| version="1.0.0" | |
| ) | |
| # Add CORS middleware | |
| # Note: When allow_credentials=True, you cannot use wildcard '*' for origins | |
| # Must specify exact origins | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["http://localhost:3000"], # Frontend origin | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Import and include routers | |
| from .routers import auth, tasks | |
| app.include_router(auth.router, prefix="/api", tags=["authentication"]) | |
| app.include_router(tasks.router, prefix="/api", tags=["tasks"]) | |
| def read_root(): | |
| return {"message": "Task Management API"} | |
| def health_check(): | |
| return {"status": "healthy"} | |
| return app | |
| app = create_app() | |
| # Create database tables on startup (for development) | |
| def on_startup(): | |
| from sqlmodel import SQLModel | |
| SQLModel.metadata.create_all(bind=engine) |