Spaces:
Runtime error
Runtime error
Download main.py from myousaf-codes/ccr-hackathon-todo: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/myousaf-codes/ccr-hackathon-todo/resolve/main/main.py
- Command line
-
hf download hf://spaces/myousaf-codes/ccr-hackathon-todo/main.py
-
curl -L -o main.py https://huggingface.co/spaces/myousaf-codes/ccr-hackathon-todo/resolve/main/main.py
1.37 kB
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from routes.tasks import router as tasks_router | |
| from routes.auth import router as auth_router | |
| from db import create_db_and_tables | |
| import os | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| # Create FastAPI app instance | |
| app = FastAPI( | |
| title="Todo Application API", | |
| description="API for managing user tasks in the Todo application", | |
| version="1.0.0" | |
| ) | |
| # Add CORS middleware to allow frontend domain | |
| frontend_url = os.getenv("FRONTEND_URL", "http://localhost:3000") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=[frontend_url], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| # Expose authorization header to allow JWT token to be accessed by frontend | |
| expose_headers=["Access-Control-Allow-Origin", "Authorization"] | |
| ) | |
| # Include task routes | |
| app.include_router(tasks_router) | |
| # Include auth routes | |
| app.include_router(auth_router) | |
| # Add health check endpoint | |
| def health_check(): | |
| return {"status": "healthy", "timestamp": __import__('datetime').datetime.now()} | |
| # Event handler to create tables on startup | |
| def on_startup(): | |
| create_db_and_tables() | |
| # Root endpoint | |
| def read_root(): | |
| return {"message": "Welcome to the Todo Application API"} |