Automated Action c1c91cc80f Fix OpenAPI documentation in production environment
- Move OpenAPI schema to root path for easier access
- Add ROOT_PATH setting to support deployments behind proxies
- Add root route that redirects to documentation
2025-05-26 11:31:16 +00:00

42 lines
1.2 KiB
Python

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.api import api_router
from app.core.config import settings
app = FastAPI(
title=settings.PROJECT_NAME,
version=settings.VERSION,
description="E-commerce API with FastAPI",
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
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins for development
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 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():
return {"status": "healthy"}
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)