From fe62af9d97c548c42548f6a371e65ebf00d06e77 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Thu, 25 Nov 2021 00:11:21 +0100 Subject: [PATCH] Allow forcing https for frontend config URLs --- api/config.dev.py | 1 + api/config.py.example | 1 + api/obs/api/app.py | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/api/config.dev.py b/api/config.dev.py index 27b685c..6711c5d 100644 --- a/api/config.dev.py +++ b/api/config.dev.py @@ -9,6 +9,7 @@ KEYCLOAK_CLIENT_ID = "portal" KEYCLOAK_CLIENT_SECRET = "c385278e-bd2e-4f13-9937-34b0c0f44c2d" DEDICATED_WORKER = True FRONTEND_URL = "http://localhost:3001/" +FRONTEND_HTTPS = False FRONTEND_DIR = None FRONTEND_CONFIG = None TILES_FILE = None # "/tiles/tiles.mbtiles" diff --git a/api/config.py.example b/api/config.py.example index 55a39c1..b1447fd 100644 --- a/api/config.py.example +++ b/api/config.py.example @@ -26,6 +26,7 @@ DEDICATED_WORKER = True # The root of the frontend. Needed for redirecting after login, and for CORS. # Set to None if frontend is served by the API. FRONTEND_URL = None +FRONTEND_HTTPS = True # Where to find the compiled frontend assets (must include index.html), or None # to disable serving the frontend. diff --git a/api/obs/api/app.py b/api/obs/api/app.py index 8b8f6e1..ba1b4c0 100644 --- a/api/obs/api/app.py +++ b/api/obs/api/app.py @@ -157,10 +157,11 @@ if INDEX_HTML and exists(INDEX_HTML): @app.get("/config.json") def get_frontend_config(req): base_path = req.server_path.replace("config.json", "") + scheme = 'https' if req.app.config.FRONTEND_HTTPS else req.scheme result = { **req.app.config.FRONTEND_CONFIG, - "apiUrl": f"{req.scheme}://{req.host}{base_path}api", - "loginUrl": f"{req.scheme}://{req.host}{base_path}login", + "apiUrl": f"{scheme}://{req.host}{base_path}api", + "loginUrl": f"{scheme}://{req.host}{base_path}login", } print(req.app.config) if req.app.config.get("TILES_FILE"):