From 80e1571f81936a749c8ce640a75001576dfdfea7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 16 Jul 2025 23:52:03 +0000 Subject: [PATCH 1/2] feat: Add PREFIX_PATH config This adds a new config `PREFIX_PATH` that is used when instantiating a StacApi by passing the router kwarg: router=APIRouter(prefix=settings.prefix_path) The new setting is documented and the default value is an empty string. --- stac_fastapi/pgstac/app.py | 3 ++- stac_fastapi/pgstac/config.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/pgstac/app.py b/stac_fastapi/pgstac/app.py index 5d42f769..cd832776 100644 --- a/stac_fastapi/pgstac/app.py +++ b/stac_fastapi/pgstac/app.py @@ -9,7 +9,7 @@ from contextlib import asynccontextmanager from brotli_asgi import BrotliMiddleware -from fastapi import FastAPI +from fastapi import APIRouter, FastAPI from stac_fastapi.api.app import StacApi from stac_fastapi.api.middleware import CORSMiddleware, ProxyHeaderMiddleware from stac_fastapi.api.models import ( @@ -171,6 +171,7 @@ async def lifespan(app: FastAPI): description=settings.stac_fastapi_description, lifespan=lifespan, ), + router=APIRouter(prefix=settings.prefix_path), settings=settings, extensions=application_extensions, client=CoreCrudClient(pgstac_search_model=post_request_model), diff --git a/stac_fastapi/pgstac/config.py b/stac_fastapi/pgstac/config.py index c8741812..15690fa4 100644 --- a/stac_fastapi/pgstac/config.py +++ b/stac_fastapi/pgstac/config.py @@ -159,11 +159,13 @@ class Settings(ApiSettings): """API settings. Attributes: + prefix_path: An optional path prefix for the underyling FastAPI router. use_api_hydrate: perform hydration of stac items within stac-fastapi. invalid_id_chars: list of characters that are not allowed in item or collection ids. """ + prefix_path: str = "" use_api_hydrate: bool = False invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache From da5505ac6b89518b8933b97c68a857814d36a5cc Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 17 Jul 2025 00:56:55 +0000 Subject: [PATCH 2/2] docs: Add PREFIX_PATH to settings documentation --- docs/settings.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/settings.md b/docs/settings.md index 9360622a..8b127507 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -62,3 +62,4 @@ In version `6.0.0` we've renamed the PG configuration variable to match the offi - `CORS_METHODS`: A list of HTTP methods that should be allowed for cross-origin requests. Defaults to `"GET,POST,OPTIONS"` - `USE_API_HYDRATE`: perform hydration of stac items within stac-fastapi - `INVALID_ID_CHARS`: list of characters that are not allowed in item or collection ids (used in Transaction endpoints) +- `PREFIX_PATH`: An optional path prefix for the underlying FastAPI router.