Skip to content

base_url used to build the urls without root_path #767

@ccancellieri

Description

@ccancellieri

Hi all,
I need to have multiple instances of this api under the same fastAPI and I'm trying to understand why base_url has been used to generate urls not using also:
f"{base_url}/{request.scope.get("root_path")}

This is preventing me to mount the application under a specific fastAPI path: all the generated urls are not shipping the root_path infact.

It works with a fixed prefix but it is kind of hardcoded routing base url which prevents me to properly use fastAPI with this library.

It would be great if we could centralise the base url management here to also use the root_path from the scope:
def get_base_url(request: Request) -> str:

My goal is to mount multiple times this library to be able to have a first level of catalogs in a single application:

"links": [
{
"rel": "self",
"type": "application/json",
"href": "http://localhost:8080/catalogs/catalog_1/"
},
{
"rel": "root",
"type": "application/json",
"href": "http://localhost:8080/catalogs/catalog_1/"
},
{
"rel": "data",
"type": "application/json",
"href": "http://localhost:8080/catalogs/catalog_1/collections"
},
{
"rel": "conformance",
"type": "application/json",
"title": "STAC/WFS3 conformance classes implemented by this server",
"href": "http://localhost:8080/catalogs/catalog_1/conformance"
},
{
"rel": "search",
"type": "application/geo+json",
"title": "STAC search",
"href": "http://localhost:8080/catalogs/catalog_1/search",
"method": "GET"
},

Related problem:
stac-utils/stac-fastapi-elasticsearch-opensearch#308 (comment)

Related questions: why we are using the state of the application to save it?
app.state.router_prefix=....

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions