From 69e8591fae02955d373737c606b89a1ae6d0442b Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Fri, 3 Dec 2021 17:54:26 +0100 Subject: [PATCH] chore: allow explicit configuration of api base url --- api/config.dev.py | 1 + api/obs/api/app.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/api/config.dev.py b/api/config.dev.py index 49d0c04..a90b212 100644 --- a/api/config.dev.py +++ b/api/config.dev.py @@ -8,6 +8,7 @@ KEYCLOAK_URL = "http://keycloak:8080/auth/realms/obs-dev/" KEYCLOAK_CLIENT_ID = "portal" KEYCLOAK_CLIENT_SECRET = "c385278e-bd2e-4f13-9937-34b0c0f44c2d" DEDICATED_WORKER = True +API_URL = "http://localhost:3000/" FRONTEND_URL = "http://localhost:3001/" FRONTEND_HTTPS = False FRONTEND_DIR = None diff --git a/api/obs/api/app.py b/api/obs/api/app.py index aeece95..6ad6b0a 100644 --- a/api/obs/api/app.py +++ b/api/obs/api/app.py @@ -117,9 +117,17 @@ async def inject_urls(req): else: req.ctx.frontend_scheme = req.scheme - req.ctx.api_scheme = req.ctx.frontend_scheme # just use the same for now - req.ctx.api_base_path = remove_right(req.server_path, req.path) - req.ctx.api_url = f"{req.ctx.frontend_scheme}://{req.host}{req.ctx.api_base_path}" + if req.app.config.get("API_URL"): + req.ctx.api_url = req.app.config.API_URL.rstrip("/") + api_url_parsed = urlparse(req.ctx.api_url) + req.ctx.api_scheme = api_url_parsed.scheme # just use the same for now + req.ctx.api_base_path = api_url_parsed.path + else: + req.ctx.api_scheme = req.ctx.frontend_scheme # just use the same for now + req.ctx.api_base_path = remove_right(req.server_path, req.path) + req.ctx.api_url = ( + f"{req.ctx.frontend_scheme}://{req.host}{req.ctx.api_base_path}" + ) if req.app.config.FRONTEND_URL: req.ctx.frontend_base_path = "/" + urlparse(