You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/27 04:09:34 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #9030: Allow using Airflow with Flask CLI

mik-laj commented on a change in pull request #9030:
URL: https://github.com/apache/airflow/pull/9030#discussion_r430800228



##########
File path: airflow/www/app.py
##########
@@ -70,6 +73,27 @@ def create_app(config=None, testing=False, app_name="Airflow"):
     app.json_encoder = AirflowJsonEncoder
 
     csrf.init_app(app)
+
+    def apply_middlewares(flask_app: Flask):
+        # Apply DispatcherMiddleware
+        base_url = urlparse(conf.get('webserver', 'base_url'))[2]
+        if not base_url or base_url == '/':
+            base_url = ""
+        flask_app.wsgi_app = DispatcherMiddleware(root_app, {base_url: flask_app.wsgi_app})  # type: ignore

Review comment:
       ```
           The actual WSGI application. This is not implemented in
           :meth:`__call__` so that middlewares can be applied without
           losing a reference to the app object. Instead of doing this::
               app = MyMiddleware(app)
           It's a better idea to do this instead::
               app.wsgi_app = MyMiddleware(app.wsgi_app)
           Then you still have the original application object around and
           can continue to call methods on it.
   ```
   https://github.com/pallets/flask/blob/330a3e3ddba712def955e7a2ccee92a205dfb656/src/flask/app.py#L2323

##########
File path: airflow/www/app.py
##########
@@ -39,15 +39,18 @@
 from airflow.utils.json import AirflowJsonEncoder
 from airflow.www.static_config import configure_manifest_files
 
-app = None  # type: Any
-appbuilder = None  # type: Optional[AppBuilder]
+app: Optional[Flask] = None
 csrf = CSRFProtect()
 
 log = logging.getLogger(__name__)
 
 
+def root_app(env, resp):
+    resp(b'404 Not Found', [('Content-Type', 'text/plain')])
+    return [b'Apache Airflow is not at this location']
+
+
 def create_app(config=None, testing=False, app_name="Airflow"):
-    global app, appbuilder

Review comment:
       This causes a side effect. We want the cache to be modified only by the cached_app method.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org