Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "root_path" config parameter for FastAPI apps #634

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add this line in the same place for the index meta-database please?

app = FastAPI(
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.
This is the "special" index meta-database.
This specification is generated using [`optimade-python-tools`](https://github.com/Materials-Consortia/optimade-python-tools/tree/v{__version__}) v{__version__}."""
),
version=__api_version__,
docs_url=f"{BASE_URL_PREFIXES['major']}/extensions/docs",
redoc_url=f"{BASE_URL_PREFIXES['major']}/extensions/redoc",
openapi_url=f"{BASE_URL_PREFIXES['major']}/extensions/openapi.json",
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I just pushed the suggested changes.

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