In some versions of Domino users may notice issues with flask app redirects. This can show up when users are being sent to a secondary page of the app or when clicking a link in the app is supposed to download a file.
If you are using a chrome browser and use developer tools (View > Developer > Developer Tools), you may see the following errors when attempting the flask redirects in your app:
Network details for the error:
Request URL: <app url>
Request Method: GET
Status Code: 302
Referrer Policy: strict-origin-when-cross-origin
or
Mixed Content: The page at '<app url> was loaded over HTTPS, but requested an
insecure resource 'http://<run_id>-domino-compute.svc.cluster.local/<userid>/
<project_name>/r/notebookSession/<runid>/<redirect_page>'. This request has been
blocked; the content must be served over HTTPS.
To remediate this issue we'll want to slightly adjust the ReverseProxied function, which we've taken from the Domino docs (found here):
class ReverseProxied(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
#flask fix
# Setting wsgi.url_scheme from Headers set by proxy before app
scheme = environ.get('HTTP_X_SCHEME', 'https')
if scheme:
environ['wsgi.url_scheme'] = scheme
# Setting HTTP_HOST from Headers set by proxy before app
remote_host = environ.get('HTTP_X_FORWARDED_HOST', '')
remote_port = environ.get('HTTP_X_FORWARDED_PORT', '')
if remote_host and remote_port:
environ['HTTP_HOST'] = f'{remote_host}:{remote_port}'
#end flaskfix
return self.app(environ, start_response)
As you can see, the only change was to add the lines between #flaskfix and #end flaskfix, posted below:
#flask fix
# Setting wsgi.url_scheme from Headers set by proxy before app
scheme = environ.get('HTTP_X_SCHEME', 'https')
if scheme:
environ['wsgi.url_scheme'] = scheme
# Setting HTTP_HOST from Headers set by proxy before app
remote_host = environ.get('HTTP_X_FORWARDED_HOST', '')
remote_port = environ.get('HTTP_X_FORWARDED_PORT', '')
if remote_host and remote_port:
environ['HTTP_HOST'] = f'{remote_host}:{remote_port}'
#end flask fix
Comments
0 comments
Please sign in to leave a comment.