From c617323375cba373b2cff12dcd0a01ed3c2f6738 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Fri, 31 May 2024 12:48:10 -0600 Subject: [PATCH] proxy-specific changes --- app/app.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/app.py b/app/app.py index 1fc7303..415737a 100644 --- a/app/app.py +++ b/app/app.py @@ -9,6 +9,9 @@ from flask import Flask, Response, render_template, request, send_from_directory from prefect.deployments import run_deployment PORT = 9021 +PROTO = "https" +BARE = True + app = Flask(__name__) logging.basicConfig(level=logging.DEBUG) @@ -22,20 +25,20 @@ def get_host(): host = os.environ.get("LIGHTNING_CLOUDSPACE_HOST") if host is None: default_host = os.environ.get("HOST_NAME", "0.0.0.0") - return f"{default_host}:{PORT}" + return f"{default_host}:{PORT}" if not BARE else f"{default_host}" else: - return f"{PORT}-{host}" + return f"{PORT}-{host}" if not BARE else f"{host}" @app.route("/iframe") @app.route("/iframe/") @app.route("/iframe/") -def home(subpath="images/animations/"): +def home(subpath="images/animations/", proto=PROTO): host = get_host() - initial_url = f"http://{host}/{subpath}" - api_url = f"http://{host}/api" + initial_url = f"{proto}://{host}/{subpath}" + api_url = f"{proto}://{host}/api" return render_template( - "index.html", initial_url=initial_url, host=f"http://{host}", api_url=api_url + "index.html", initial_url=initial_url, host=f"{proto}://{host}", api_url=api_url ) @@ -70,10 +73,10 @@ def custom_static(filename): @app.route("/", methods=["GET"]) @app.route("/", methods=["GET"]) -def proxy(url=""): +def proxy(url="", proto=PROTO): original_base_url = "https://services.swpc.noaa.gov" host = get_host() - proxy_base_url = f"http://{host}/" + proxy_base_url = f"{proto}://{host}/" target_url = f"{original_base_url}/{url}" logging.debug(f"Fetching URL: {target_url}")