diff --git a/app/core/config.py b/app/core/config.py index d67bdf3..c07332b 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -8,6 +8,7 @@ class Settings(BaseSettings): PROJECT_NAME: str = "E-Commerce API" VERSION: str = "0.1.0" API_V1_STR: str = "/api/v1" + ROOT_PATH: str = "" # For deployments behind proxies/subpaths, can be set via env var # CORS Settings CORS_ORIGINS: List[str] = ["*"] # Allow all origins for development diff --git a/main.py b/main.py index 5a96dfb..4d7e9f5 100644 --- a/main.py +++ b/main.py @@ -9,9 +9,10 @@ app = FastAPI( title=settings.PROJECT_NAME, version=settings.VERSION, description="E-commerce API with FastAPI", - openapi_url=f"{settings.API_V1_STR}/openapi.json", + openapi_url="/openapi.json", # Make OpenAPI schema available at root path docs_url="/docs", redoc_url="/redoc", + root_path=settings.ROOT_PATH, # Support for deployments behind a proxy/subdirectory ) # Set CORS middleware @@ -26,6 +27,12 @@ app.add_middleware( # Include API router app.include_router(api_router, prefix=settings.API_V1_STR) +# Root route to redirect to documentation +@app.get("/", include_in_schema=False) +async def root(): + from fastapi.responses import RedirectResponse + return RedirectResponse(url="/docs") + # Health check endpoint @app.get("/health", tags=["Health"]) async def health_check():