blitz_api/app/server.py
fusion44 25e4be8441 feat: make config loading more flexible
If the environment variable BAPI_ENV_PATH is set, the config system will
try to read configs from the given path instead of .env in pwd

If no file is found .env in pwd will be used as a fallback

Env variables will always override settings in .env files.
2025-03-23 17:43:39 +01:00

33 lines
822 B
Python

import uvicorn
import click # isort:skip
from app.api.config import config
@click.command()
@click.option("--port", default="5000", help="Port to run Blitz API on")
@click.option("--host", default="127.0.0.1", help="Host to run Blitz API on")
@click.option(
"--root_path",
default=None,
help="Set the ASGI 'root_path' for applications submounted below a given URL path.",
)
def main(port, host, root_path):
"""Launched with `poetry run api` at root level"""
p = ""
if root_path is not None and root_path != "":
p = root_path
else:
p = str(config("BAPI_ROOT_PATH", default=""))
if p == "/":
root_path = ""
print(f"launching with {host}:{port}{p}")
uvicorn.run("app.main:app", port=port, host=host, root_path=p)
if __name__ == "__main__":
main()