From 3f6b3137b8d1d34eea047aa5ed7e59c09984a4d2 Mon Sep 17 00:00:00 2001 From: sjaek Date: Wed, 20 Jan 2021 16:22:25 +0100 Subject: [PATCH] Add werkzeug ProxyFix X-Forwarded-Prefix support The base url is not the same as the blueprint mount point because the blueprint url is relative to the application context root. So either the jinja template needs to be altered to use relative urls, or the base_url should be determined per request. This commit changes the base_url to url_for(".show"), this makes the UI work for both proxied and direct requests. --- flask_swagger_ui/flask_swagger_ui.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/flask_swagger_ui/flask_swagger_ui.py b/flask_swagger_ui/flask_swagger_ui.py index 5c0886c..6f7b56e 100644 --- a/flask_swagger_ui/flask_swagger_ui.py +++ b/flask_swagger_ui/flask_swagger_ui.py @@ -1,6 +1,6 @@ import os import json -from flask import Blueprint, send_from_directory, render_template, request +from flask import Blueprint, send_from_directory, render_template, request, url_for def get_swaggerui_blueprint( @@ -28,7 +28,6 @@ def get_swaggerui_blueprint( fields = { # Some fields are used directly in template - "base_url": base_url, "app_name": default_config.pop("app_name"), # Rest are just serialized into json string for inclusion in the .js file "config_json": json.dumps(default_config), @@ -49,7 +48,7 @@ def show(path=None): } ) fields["config_json"] = json.dumps(default_config) - return render_template("index.template.html", **fields) + return render_template("index.template.html", base_url=url_for(".show"), **fields) else: return send_from_directory( # A bit of a hack to not pollute the default /static path with our files.