Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f46c2e6

Browse files
committed
Fix ProxyFix Imported Twice
ProxyFix was imported in the global imports, and then conditionally imported again in the main block. Moved the conditional import to be a component of the global import function instead of in the main block, and added comments about using this as a module and still using the ProxyFix.
1 parent 71db5c9 commit f46c2e6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

index.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010
import hmac
1111
from hashlib import sha1
1212
from flask import Flask, request, abort
13-
from werkzeug.contrib.fixers import ProxyFix
13+
14+
"""
15+
Conditionally import ProxyFix from werkzeug if the USE_PROXYFIX environment
16+
variable is set to true. If you intend to import this as a module in your own
17+
code, use os.environ to set the environment variable before importing this as a
18+
module.
19+
20+
.. code:: python
21+
22+
os.environ['USE_PROXYFIX'] = 'true'
23+
import flask-github-webhook-handler.index as handler
24+
25+
"""
26+
if os.environ.get('USE_PROXYFIX', None) == 'true':
27+
from werkzeug.contrib.fixers import ProxyFix
1428

1529
app = Flask(__name__)
1630
app.debug = os.environ.get('DEBUG') == 'true'
@@ -109,7 +123,5 @@ def compare_digest(a, b):
109123
port_number = int(sys.argv[1])
110124
except:
111125
port_number = 80
112-
if os.environ.get('USE_PROXYFIX', None) == 'true':
113-
from werkzeug.contrib.fixers import ProxyFix
114126
app.wsgi_app = ProxyFix(app.wsgi_app)
115127
app.run(host='0.0.0.0', port=port_number)

0 commit comments

Comments
 (0)