Created
October 31, 2019 17:16
-
-
Save snivas/b2398f3328b10730fb559253ebbb902b to your computer and use it in GitHub Desktop.
FLASK_APP_MUTATOR Superset example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def attach_handler(app): | |
from flask import redirect, url_for | |
app.wsgi_app = CustomProxyFix(app.wsgi_app) | |
class CustomProxyFix(object): | |
def __init__(self, app): | |
self.app = app | |
def __call__(self, environ, start_response): | |
host = environ.get('HTTP_X_FHOST', '') | |
if host: | |
environ['HTTP_HOST'] = host | |
return self.app(environ, start_response) | |
FLASK_APP_MUTATOR = lambda app: attach_handler(app) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def attach_handler(app): | |
from flask import redirect, url_for | |
@app.before_request | |
def beforerequest(): | |
print("before_request!") | |
@app.after_request | |
def afterrequest(response): | |
print("after_request is running!") | |
return response | |
FLASK_APP_MUTATOR = lambda app: attach_handler(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment