Skip to content

Commit edd6f47

Browse files
committed
Add CustomUvicornWorker to support dynamic root path configuration
1 parent 4012f6a commit edd6f47

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

app/app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import time
22
from contextlib import asynccontextmanager
3+
import os
34

5+
from uvicorn.workers import UvicornWorker
46
from fastapi import FastAPI
57
from fastapi.middleware.cors import CORSMiddleware
68
from fastapi.middleware.gzip import GZipMiddleware
@@ -94,6 +96,13 @@ async def add_extra_headers(request: Request, call_next):
9496
return response
9597

9698

99+
class CustomUvicornWorker(UvicornWorker):
100+
CONFIG_KWARGS = {}
101+
root_path = os.environ.get("ROOT_PATH", "")
102+
if root_path:
103+
CONFIG_KWARGS.update({"root_path": root_path})
104+
105+
97106
def custom_openapi():
98107
if not app.openapi_schema:
99108
app.openapi_schema = get_openapi(

app/gunicorn_conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
keepalive = 5
99
threads = 10
1010
workers = 3
11-
worker_class = "uvicorn.workers.UvicornWorker"
11+
worker_class = "app.app.CustomUvicornWorker"

0 commit comments

Comments
 (0)