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

Conversation

markus1978
Copy link
Contributor

…pi app root_path.

Fastapi allows to configure a root_path in cases where the app cannot be served directly at the path root. This is meaningful if you need to serve multiple apps/sites from the same host or have other constraints and need to put optimade "somewhere else". We for example want to mount optimade into another fastapi app (alongside our proprietary API, see fastapi docs), other might need to proxy optimade with a path prefix (see fastapi docs here).

@codecov
Copy link

codecov bot commented Dec 22, 2020

Codecov Report

Merging #634 (ee056f7) into master (e20407d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #634   +/-   ##
=======================================
  Coverage   93.27%   93.27%           
=======================================
  Files          60       60           
  Lines        3256     3257    +1     
=======================================
+ Hits         3037     3038    +1     
  Misses        219      219           
Flag Coverage Δ
project 93.27% <100.00%> (+<0.01%) ⬆️
validator 66.90% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/server/main.py 94.23% <ø> (ø)
optimade/server/main_index.py 94.44% <ø> (ø)
optimade/server/config.py 88.23% <100.00%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e20407d...ee056f7. Read the comment docs.

@markus1978 markus1978 force-pushed the added-root-path branch 2 times, most recently from c24d391 to 02306f8 Compare December 22, 2020 08:19
@ml-evs ml-evs requested a review from CasperWA December 22, 2020 09:46
Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Thanks for this @markus1978, looks useful.

Comment on lines 80 to 81
"Fastapi root_path app 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."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Fastapi root_path app 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."
"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."

@@ -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.

@ml-evs ml-evs changed the title Added a root_path config parameter that allows to configure the fasta… Added "root_path" config parameter for FastAPI.app Dec 22, 2020
Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @markus1978.

@ml-evs ml-evs changed the title Added "root_path" config parameter for FastAPI.app Added "root_path" config parameter for FastAPI apps Dec 22, 2020
@ml-evs ml-evs merged commit 322cbc5 into Materials-Consortia:master Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants