fix(api): configure root_path for OpenAPI docs behind reverse proxy
Add ROOT_PATH environment variable support so FastAPI generates correct URLs for Swagger UI when served behind nginx at /api. This fixes the "invalid version field" error when accessing /api/docs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -161,6 +161,7 @@ app = FastAPI(
|
|||||||
description="Semiconductor Patent & Analytics Report Core - Patent portfolio analysis using AI",
|
description="Semiconductor Patent & Analytics Report Core - Patent portfolio analysis using AI",
|
||||||
version="1.0.0",
|
version="1.0.0",
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
|
root_path=config.root_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add CORS middleware for React frontend
|
# Add CORS middleware for React frontend
|
||||||
|
|||||||
@@ -25,3 +25,7 @@ use_cache = os.getenv("USE_CACHE", "true").lower() in ("true", "1", "yes")
|
|||||||
# Legacy compatibility - USE_DATABASE is deprecated, database is always used
|
# Legacy compatibility - USE_DATABASE is deprecated, database is always used
|
||||||
# This variable is kept for backwards compatibility but has no effect
|
# This variable is kept for backwards compatibility but has no effect
|
||||||
use_database = os.getenv("USE_DATABASE", "false").lower() in ("true", "1", "yes")
|
use_database = os.getenv("USE_DATABASE", "false").lower() in ("true", "1", "yes")
|
||||||
|
|
||||||
|
# Root path for running behind a reverse proxy (e.g., "/api" when served at /api/)
|
||||||
|
# This ensures OpenAPI docs work correctly when accessed via the proxy
|
||||||
|
root_path = os.getenv("ROOT_PATH", "")
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ services:
|
|||||||
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/sparc
|
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/sparc
|
||||||
USE_CACHE: "true"
|
USE_CACHE: "true"
|
||||||
JWT_SECRET: ${JWT_SECRET:-sparc-secret-key-change-in-production}
|
JWT_SECRET: ${JWT_SECRET:-sparc-secret-key-change-in-production}
|
||||||
|
ROOT_PATH: /api
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
Reference in New Issue
Block a user