From 94062c2d64b9fb209ece57b9fd7885a0dfd9a053 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Mon, 18 Jan 2021 18:19:25 +0100 Subject: [PATCH] apply proxy fix --- cellxgene_gateway/gateway.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index 723d488..dfea656 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -25,7 +25,7 @@ from flask import ( ) from flask_api import status from werkzeug.utils import secure_filename - +from werkzeug.middleware.proxy_fix import ProxyFix from cellxgene_gateway import env from cellxgene_gateway.backend_cache import BackendCache from cellxgene_gateway.cache_entry import CacheEntryStatus @@ -50,6 +50,7 @@ def _force_https(app): app.wsgi_app = _force_https(app.wsgi_app) +app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1) cache = BackendCache() location = f"{env.external_protocol}://{env.external_host}" @@ -149,11 +150,7 @@ def upload_file(): if "file" in request.files: f = request.files["file"] if f and f.filename.endswith(".h5ad"): - f.save( - os.path.join( - full_upload_path, secure_filename(f.filename) - ) - ) + f.save(os.path.join(full_upload_path, secure_filename(f.filename))) return redirect("/filecrawl.html", code=302) else: raise CellxgeneException( @@ -166,21 +163,15 @@ def upload_file(): status.HTTP_400_BAD_REQUEST, ) else: - raise CellxgeneException( - "Invalid directory.", status.HTTP_400_BAD_REQUEST - ) + raise CellxgeneException("Invalid directory.", status.HTTP_400_BAD_REQUEST) return redirect(location, code=302) if env.enable_upload: app.add_url_rule("/make_user", "make_user", make_user, methods=["POST"]) - app.add_url_rule( - "/make_subdir", "make_subdir", make_subdir, methods=["POST"] - ) - app.add_url_rule( - "/upload_file", "upload_file", upload_file, methods=["POST"] - ) + app.add_url_rule("/make_subdir", "make_subdir", make_subdir, methods=["POST"]) + app.add_url_rule("/upload_file", "upload_file", upload_file, methods=["POST"]) def set_no_cache(resp):