Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions backend/qualibrate_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from qualibrate_app.config.resolvers import (
get_config_path,
get_cors_origin,
get_default_static_files_path,
get_settings,
)
Expand All @@ -25,18 +26,12 @@
docs_url="/app_docs",
)
_settings = get_settings(get_config_path())

origins = [
"http://localhost:8002",
"http://localhost:8001",
"http://127.0.0.1:8002",
"http://127.0.0.1:8001",
]
cors_origins = get_cors_origin()

app.add_middleware(QualibrateCatchExcMiddleware)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_origins=cors_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
16 changes: 15 additions & 1 deletion backend/qualibrate_app/cli/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)

from qualibrate_app.config import CONFIG_PATH_ENV_NAME
from qualibrate_app.config.vars import CORS_ORIGINS_ENV_NAME


@click.command(name="start")
Expand All @@ -33,8 +34,21 @@
show_default=True,
help="Application will be started on the given port",
) # env QUALIBRATE_START_PORT
def start_command(config_path: Path, port: int, reload: bool) -> None:
@click.option(
"--cors-origin",
type=str,
multiple=True,
help="CORS origin to use. Can be passed multiple times.",
)
def start_command(
config_path: Path,
port: int,
reload: bool,
cors_origin: list[str],
) -> None:
os.environ[CONFIG_PATH_ENV_NAME] = str(config_path)
if len(cors_origin) != 0:
os.environ[CORS_ORIGINS_ENV_NAME] = ",".join(cors_origin)

from qualibrate_app.app import main as app_main

Expand Down
16 changes: 16 additions & 0 deletions backend/qualibrate_app/config/resolvers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import warnings
from functools import lru_cache
from itertools import product
from pathlib import Path
from typing import Annotated, Optional

Expand All @@ -15,11 +16,13 @@

from qualibrate_app.config.vars import (
CONFIG_PATH_ENV_NAME,
CORS_ORIGINS_ENV_NAME,
)

__all__ = [
"get_default_static_files_path",
"get_config_path",
"get_cors_origin",
"get_settings",
"get_quam_state_path",
]
Expand All @@ -43,6 +46,19 @@ def get_config_path() -> Path:
return get_qualibrate_config_path()


@lru_cache
def get_cors_origin() -> list[str]:
cors_env = os.environ.get(CORS_ORIGINS_ENV_NAME)
if cors_env is not None:
return list(cors_env.split(","))
return list(
f"http://{host}:{port}"
for host, port in product(
["localhost", "127.0.0.1"], [1234, 8000, 8001]
)
)


@lru_cache
def get_settings(
config_path: Annotated[Path, Depends(get_config_path)],
Expand Down
1 change: 1 addition & 0 deletions backend/qualibrate_app/config/vars.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_PATH_ENV_NAME = "QUALIBRATE_APP_CONFIG_FILE"
CORS_ORIGINS_ENV_NAME = "QUALIBRATE_APP_CORS_ORIGINS"

METADATA_OUT_PATH = "data_path"
Loading