Fix Swagger UI behind nginx - add root_path for /api proxy
Some checks failed
CI / build (18.x) (push) Has been cancelled
CI / build (20.x) (push) Has been cancelled

This commit is contained in:
Khoa.vo 2026-01-13 09:32:04 +07:00
parent 174cb75f23
commit 037c80c4fd
2 changed files with 10 additions and 2 deletions

View file

@ -125,6 +125,7 @@ stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0 stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0 stderr_logfile_maxbytes=0
environment=API_ROOT_PATH="/api"
EOF EOF
# Set permissions # Set permissions

View file

@ -33,6 +33,12 @@ async def lifespan(app: FastAPI):
print("👋 KV-Pix FastAPI Backend shutting down...") 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( app = FastAPI(
title="KV-Pix API", title="KV-Pix API",
description=""" 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. All generation endpoints require provider-specific cookies passed in the request body.
See the Settings page in the web app for cookie configuration instructions. See the Settings page in the web app for cookie configuration instructions.
""", """,
version="1.0.0", version="3.2.0",
lifespan=lifespan, lifespan=lifespan,
docs_url="/docs", docs_url="/docs",
redoc_url="/redoc" redoc_url="/redoc",
root_path=ROOT_PATH,
) )
# CORS middleware - allow Next.js frontend # CORS middleware - allow Next.js frontend