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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #634 +/- ##
=======================================
Coverage 93.27% 93.27%
=======================================
Files 60 60
Lines 3256 3257 +1
=======================================
+ Hits 3037 3038 +1
Misses 219 219
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
c24d391
to
02306f8
Compare
There was a problem hiding this 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.
optimade/server/config.py
Outdated
"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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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, |
There was a problem hiding this comment.
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?
optimade-python-tools/optimade/server/main_index.py
Lines 38 to 50 in e20407d
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", | |
) |
There was a problem hiding this comment.
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.
…pi app root_path.
02306f8
to
ee056f7
Compare
There was a problem hiding this 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.
…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).