From 037c80c4fdc74dee0213a42aa5f5dead8a61ff79 Mon Sep 17 00:00:00 2001 From: "Khoa.vo" Date: Tue, 13 Jan 2026 09:32:04 +0700 Subject: [PATCH] Fix Swagger UI behind nginx - add root_path for /api proxy --- Dockerfile | 1 + backend/main.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index eef9157..4965151 100644 --- a/Dockerfile +++ b/Dockerfile @@ -125,6 +125,7 @@ stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 +environment=API_ROOT_PATH="/api" EOF # Set permissions diff --git a/backend/main.py b/backend/main.py index fa0901f..f080e90 100644 --- a/backend/main.py +++ b/backend/main.py @@ -33,6 +33,12 @@ async def lifespan(app: FastAPI): print("👋 KV-Pix FastAPI Backend shutting down...") +import os + +# Detect if running behind nginx proxy (via env var) +# When behind nginx at /api, set root_path so Swagger knows correct URL prefix +ROOT_PATH = os.getenv("API_ROOT_PATH", "") + app = FastAPI( title="KV-Pix API", description=""" @@ -50,10 +56,11 @@ A powerful API for AI image generation using multiple providers. All generation endpoints require provider-specific cookies passed in the request body. See the Settings page in the web app for cookie configuration instructions. """, - version="1.0.0", + version="3.2.0", lifespan=lifespan, docs_url="/docs", - redoc_url="/redoc" + redoc_url="/redoc", + root_path=ROOT_PATH, ) # CORS middleware - allow Next.js frontend