From 4ddf1ed861fdd14cc81fa144b7dd896e5b69f2a8 Mon Sep 17 00:00:00 2001 From: Giovanni Savarese Date: Fri, 12 Jul 2024 11:50:31 +0000 Subject: [PATCH] feat: add ROOT_PATH to settings --- fed_reg/config.py | 7 ++++++- fed_reg/main.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fed_reg/config.py b/fed_reg/config.py index e8d6f8a6..b80692e7 100644 --- a/fed_reg/config.py +++ b/fed_reg/config.py @@ -23,6 +23,7 @@ class Settings(BaseSettings): PROJECT_NAME: str = "Federation-Registry" DOMAIN: str = "localhost:8000" API_V1_STR: str = "/api/v1" + ROOT_PATH: str | None = None @validator("API_V1_STR") @classmethod @@ -81,7 +82,11 @@ def create_doc_url(cls, v: Optional[str], values: Dict[str, Any]) -> str: if v: return v protocol = "http" - link = os.path.join(values.get("DOMAIN"), values.get("API_V1_STR")[1:], "docs") + root_path = values.get("ROOT_PATH", "/") + root_path = root_path[1:] if root_path is not None else "" + link = os.path.join( + values.get("DOMAIN"), root_path, values.get("API_V1_STR")[1:], "docs" + ) return f"{protocol}://{link}" # BACKEND_CORS_ORIGINS is a JSON-formatted list of origins diff --git a/fed_reg/main.py b/fed_reg/main.py index be5d096e..e77fc9f2 100644 --- a/fed_reg/main.py +++ b/fed_reg/main.py @@ -43,6 +43,7 @@ summary=summary, title=settings.PROJECT_NAME, version=version, + root_path=settings.ROOT_PATH, ) # if settings.BACKEND_CORS_ORIGINS: # app.add_middleware(