import logging from datetime import datetime from fastapi import Depends, FastAPI, HTTPException from fastapi.responses import HTMLResponse, RedirectResponse from fastapi.middleware.cors import CORSMiddleware from sqlalchemy import text from sqlalchemy.orm import Session from app.api.main import api_router from app.core.config import settings from app.core.database import get_db from app.core.lifespan import lifespan logger = logging.getLogger(__name__) # FastAPI app with lifespan app = FastAPI( title=settings.project_name, description=settings.description, version=settings.version, lifespan=lifespan, ) # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=settings.allowed_hosts, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include API router app.include_router(api_router, prefix="/api/v1") # Public Routes (no authentication required) # Core application endpoints (Public Routes, no authentication required) @app.get("/", include_in_schema=False) async def root(): """Redirect root to documentation""" return RedirectResponse(url="/documentation") @app.get("/health") def health_check(db: Session = Depends(get_db)): """Health check endpoint""" try: # Test database connection db.execute(text("SELECT 1")) return {"status": "healthy", "timestamp": datetime.utcnow(), "message": f"{settings.project_name} v{settings.version}", "docs": { "swagger": "/docs", "redoc": "/redoc", "openapi": "/openapi.json", "complete": "Documentation site URL here" }, "features": [ "JWT Authentication", "Marketplace-aware product import", "Multi-shop product management", "Stock management with location tracking", ], "supported_marketplaces": [ "Letzshop", ], "auth_required": "Most endpoints require Bearer token authentication", } except Exception as e: logger.error(f"Health check failed: {e}") raise HTTPException(status_code=503, detail="Service unhealthy") # Add this temporary endpoint to your router: # Documentation redirect endpoints @app.get("/documentation", response_class=HTMLResponse, include_in_schema=False) async def documentation_page(): """Enhanced documentation hub page""" return """
Choose your documentation experience
Swagger UI interface for testing API endpoints directly in your browser. Perfect for development and API exploration.
Clean, readable API documentation with ReDoc. Great for understanding API structure and parameters.
Comprehensive project documentation with guides, tutorials, architecture, and development info.
Step-by-step installation and setup guide to get you up and running quickly.
Testing conventions, how to run tests, and contribute to the test suite.
Check the current status and health of the API and its dependencies.
Need help? Check our GitHub Issues