Skip to content

Commit 3245685

Browse files
committed
added back ProxyFix
1 parent db5ef0c commit 3245685

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/cs50/flask.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,19 @@ def _after(*args, **kwargs):
4242
logging.getLogger("cs50").disabled = disabled
4343
SQL.execute = _after
4444

45+
# When behind CS50 IDE's proxy, ensure that flask.redirect doesn't redirect from HTTPS to HTTP
46+
# https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#module-werkzeug.middleware.proxy_fix
47+
if getenv("C9_HOSTNAME") and not getenv("IDE_OFFLINE"):
48+
try:
49+
import flask
50+
from werkzeug.middleware.proxy_fix import ProxyFix
51+
_before = flask.Flask.__init__
52+
def _after(*args, **kwargs):
53+
_before(*args, **kwargs)
54+
self.wsgi_app = ProxyFix(self.wsgi_app, x_proto=1)
55+
flask.Flask.__init__ = _after
56+
except:
57+
pass
58+
4559
except Exception:
4660
pass

0 commit comments

Comments
 (0)