summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2018-10-11 17:16:18 +0200
committerYuval Adam <_@yuv.al>2018-10-11 17:16:18 +0200
commit1f15c7efcc5e9a32e69eeebb22148c2c3a4fc5d7 (patch)
treeda29582d22dcd09a0de688974c5cf38fbeebeac4 /app.py
parent17bb72e403c2d29793640cba2fef99e1414c4465 (diff)
Cleanup get_ip()
Diffstat (limited to 'app.py')
-rw-r--r--app.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/app.py b/app.py
index 5d4da22..85bfd62 100644
--- a/app.py
+++ b/app.py
@@ -3,6 +3,8 @@ from os import environ
app = Flask(__name__)
+env = 'PROD' if 'PROD' in environ else 'DEV'
+
TEMPLATE = '''
/----------------------------------------\\
| {ip:39}|
@@ -14,14 +16,14 @@ TEMPLATE = '''
'''
def get_ip(request):
- if 'PROD' in environ:
+ FOWARDED_FOR_HEADER = 'X-Forwarded-For'
+ if FOWARDED_FOR_HEADER in request.headers:
# Routing layers and proxies along the way might mask the original IP
# So fetch it from the custom header
# And make sure we just take the first (source) IP address
- ips = request.headers.get('X-Forwarded-For')
+ ips = request.headers.get(FOWARDED_FOR_HEADER)
return ips.split(',')[0]
- else:
- return request.remote_addr
+ return request.remote_addr
@app.route('/')
def index():