Spaces:
Sleeping
Sleeping
Download build/lib/main.py from hashir-qt/tasklert-api: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/spaces/hashir-qt/tasklert-api/resolve/main/build/lib/main.py
- Command line
-
hf download hf://spaces/hashir-qt/tasklert-api/build/lib/main.py
-
curl -L -o main.py https://huggingface.co/spaces/hashir-qt/tasklert-api/resolve/main/build/lib/main.py
1.63 kB
| """Main FastAPI application for the Phase II Full-Stack Todo App.""" | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from .api.auth import router as auth_router | |
| from .api.todos import router as todos_router | |
| from .core.config import settings | |
| from .core.database import create_db_and_tables | |
| # Create FastAPI app instance | |
| app = FastAPI( | |
| title=settings.app_name, | |
| description="REST API for the Full-Stack Todo Application with authentication", | |
| version=settings.version, | |
| debug=settings.debug, | |
| ) | |
| # Add CORS middleware | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=[settings.frontend_url, "http://localhost:3000", "http://localhost:3001"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| # Expose authorization header to frontend | |
| expose_headers=["Access-Control-Allow-Origin", "Authorization"] | |
| ) | |
| # Include API routers | |
| app.include_router(auth_router) | |
| app.include_router(todos_router) | |
| async def on_startup(): | |
| """Create database tables on startup.""" | |
| create_db_and_tables() | |
| async def root(): | |
| """Root endpoint for health check.""" | |
| return {"message": "Welcome to Phase II Full-Stack Todo App API"} | |
| async def health_check(): | |
| """Health check endpoint.""" | |
| from .core.database import db_health_check | |
| db_ok = await db_health_check() | |
| return { | |
| "status": "healthy", | |
| "database": "ok" if db_ok else "unavailable" | |
| } | |
| # For running with uvicorn | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=8000) |