stac-fastapi
stac-fastapi copied to clipboard
Inclusion of root-path prefix in paths available from service-desc when hosted behind a proxy
Current and expected behavior As discussed in #489, when STAC-fastapi is hosted behind a proxy and started with a command like the following:
uvicorn --root-path "/stac" --proxy-headers stac_fastapi.sqlalchemy.app:app
All the links rendered by the application are the ones expected and they can be used to reach the various endpoints supported by the application. The only notable exception is inside the service-desc located under /stac/api, this endpoint is reachable but its content provides broken links since none of them include the expected root-path prefix (/stac in our specific case).
Current
{
"openapi": "3.0.2",
"info": {
"title": "stac-fastapi",
"version": "0.1"
},
"paths": {
"/": {
"get": {
"summary": "Landing Page",
"description": "Endpoint.",
"operationId": "Landing_Page__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/conformance": {
"get": {
"summary": "Conformance Classes",
"description": "Endpoint.",
"operationId": "Conformance_Classes_conformance_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/collections/{collection_id}/items/{item_id}": {
"get": {
"summary": "Get Item",
"description": "Endpoint.",
"operationId": "Get_Item_collections__collection_id__items__item_id__get",
"parameters": [
...
Expected
{
"openapi": "3.0.2",
"info": {
"title": "stac-fastapi",
"version": "0.1"
},
"paths": {
"/stac/": {
"get": {
"summary": "Landing Page",
"description": "Endpoint.",
"operationId": "Landing_Page__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/stac/conformance": {
"get": {
"summary": "Conformance Classes",
"description": "Endpoint.",
"operationId": "Conformance_Classes_conformance_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/stac/collections/{collection_id}/items/{item_id}": {
"get": {
"summary": "Get Item",
"description": "Endpoint.",
"operationId": "Get_Item_collections__collection_id__items__item_id__get",
"parameters": [
...
The omission of the root-path prefix makes all the potential interactions with the API available inside the api.html page with Try it out buttons unusable as it returns 404 errors.
The issue can be worked around by creating a custom StacApi class as illustrated here https://github.com/microsoft/planetary-computer-apis/blob/main/pcstac/pcstac/api.py#L22-L26, but as running behind a proxy could be a common use case for many deployments, it might make sense to pull this feature directly into stac-fastapi.