Skip to content

Commit

Permalink
Added "root_path" config parameter for FastAPI apps (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
markus1978 authored Dec 22, 2020
1 parent e20407d commit 322cbc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions optimade/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class ServerConfig(BaseSettings):
"test_server",
description="ID of /links endpoint resource for the chosen default OPTIMADE implementation (only relevant for the index meta-database)",
)
root_path: Optional[str] = Field(
None,
description=(
"Sets the FastAPI app `root_path` parameter. This can be used to serve the API under a "
"path prefix behind a proxy or as a sub-application of another FastAPI app. "
"See https://fastapi.tiangolo.com/advanced/sub-applications/#technical-details-root_path for details."
),
)
base_url: Optional[str] = Field(
None, description="Base URL for this implementation"
)
Expand Down
1 change: 1 addition & 0 deletions optimade/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
LOGGER.info("DEBUG MODE")

app = FastAPI(
root_path=CONFIG.root_path,
title="OPTIMADE API",
description=(
f"""The [Open Databases Integration for Materials Design (OPTIMADE) consortium](https://www.optimade.org/) aims to make materials databases interoperational by developing a common REST API.
Expand Down
1 change: 1 addition & 0 deletions optimade/server/main_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


app = FastAPI(
root_path=CONFIG.root_path,
title="OPTIMADE API - Index meta-database",
description=(
f"""The [Open Databases Integration for Materials Design (OPTIMADE) consortium](https://www.optimade.org/) aims to make materials databases interoperational by developing a common REST API.
Expand Down

0 comments on commit 322cbc5

Please sign in to comment.