tasklert-api / build /lib /main.py
hashir-qt's picture
initial deploy
507973e
Raw History Blame Contribute Delete
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)
@app.on_event("startup")
async def on_startup():
"""Create database tables on startup."""
create_db_and_tables()
@app.get("/")
async def root():
"""Root endpoint for health check."""
return {"message": "Welcome to Phase II Full-Stack Todo App API"}
@app.get("/health")
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)