From 2815deb22113d10a029488303c6a6ba5d6445bb3 Mon Sep 17 00:00:00 2001 From: 0xWheatyz Date: Sun, 15 Mar 2026 11:48:11 -0400 Subject: [PATCH] fix(api): configure root_path for OpenAPI docs behind reverse proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- SPARC/api.py | 1 + SPARC/config.py | 4 ++++ docker-compose.yml | 1 + 3 files changed, 6 insertions(+) diff --git a/SPARC/api.py b/SPARC/api.py index cf76493..482caab 100644 --- a/SPARC/api.py +++ b/SPARC/api.py @@ -161,6 +161,7 @@ app = FastAPI( description="Semiconductor Patent & Analytics Report Core - Patent portfolio analysis using AI", version="1.0.0", lifespan=lifespan, + root_path=config.root_path, ) # Add CORS middleware for React frontend diff --git a/SPARC/config.py b/SPARC/config.py index 11a12a2..1612b75 100644 --- a/SPARC/config.py +++ b/SPARC/config.py @@ -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 # This variable is kept for backwards compatibility but has no effect 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", "") diff --git a/docker-compose.yml b/docker-compose.yml index 7aa4e63..7bbdbe2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,6 +38,7 @@ services: DATABASE_URL: postgresql://postgres:postgres@postgres:5432/sparc USE_CACHE: "true" JWT_SECRET: ${JWT_SECRET:-sparc-secret-key-change-in-production} + ROOT_PATH: /api ports: - "8000:8000" depends_on: