from pathlib import Path import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.api.routes import api_router from app.core.config import settings app = FastAPI( title="NoteTaker", description="A Note Taking API with FastAPI and SQLite", version="0.1.0", openapi_url="/openapi.json", docs_url="/docs", redoc_url="/redoc", ) # Set up CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include API routes app.include_router(api_router, prefix=settings.API_V1_STR) # Create necessary directories storage_path = Path("/app/storage") storage_path.mkdir(parents=True, exist_ok=True) db_path = storage_path / "db" db_path.mkdir(parents=True, exist_ok=True) @app.get("/", tags=["root"]) async def root(): """ Root endpoint that returns basic app information. """ return { "app_name": settings.PROJECT_NAME, "description": "A Note Taking API with FastAPI and SQLite", "version": "0.1.0", "docs": "/docs", "redoc": "/redoc", "health": "/health", "openapi": "/openapi.json", } @app.get("/health", tags=["health"]) async def health_check(): """ Health check endpoint to verify the API is running properly. """ return {"status": "healthy", "service": settings.PROJECT_NAME} if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)