added middleware for emulation #76

Merged
Ghost merged 2 commits from georgdeamon into main 2024-01-28 18:37:23 +00:00
2 changed files with 14 additions and 2 deletions
Showing only changes of commit 3828402865 - Show all commits

View File

@@ -5,7 +5,11 @@ cors_url = [
"http://0.0.0.0", "http://0.0.0.0",
"http://[::]", "http://[::]",
] ]
cors_ports = ["*", 3000, 2979] cors_ports = ["*", 3000, 2979, 8001, 8002]
cors_whitelist = []
for u in cors_url:
for p in cors_ports:
cors_whitelist.append(f"{u}:{p}")
# host for the server, frontend, backend and emulators # host for the server, frontend, backend and emulators
host = "127.0.0.1" host = "127.0.0.1"

View File

@@ -11,6 +11,7 @@ from fastapi.responses import HTMLResponse, JSONResponse
# Importing configuration and schemas from the clan_cli package # Importing configuration and schemas from the clan_cli package
import clan_cli.config as config import clan_cli.config as config
from clan_cli.webui.schemas import Resolution from clan_cli.webui.schemas import Resolution
from fastapi.middleware.cors import CORSMiddleware
# Creating FastAPI instances for different applications # Creating FastAPI instances for different applications
app_dlg = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True}) app_dlg = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True})
@@ -25,7 +26,14 @@ apps = [
(app_c1, config.c1_port), (app_c1, config.c1_port),
(app_c2, config.c2_port), (app_c2, config.c2_port),
] ]
for app, port in apps:
app.add_middleware(
CORSMiddleware,
allow_origins=config.cors_whitelist,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Healthcheck endpoints for different applications # Healthcheck endpoints for different applications
@app_c1.get("/") @app_c1.get("/")