chore: allow explicit configuration of api base url

This commit is contained in:
Paul Bienkowski 2021-12-03 17:54:26 +01:00
parent 09fe1a7ac0
commit 69e8591fae
2 changed files with 12 additions and 3 deletions

View file

@ -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

View file

@ -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(