From 51adc564bb2aa0c60d6d9a14b2506d8601dcf50e Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 21 Dec 2020 11:16:49 -0500 Subject: [PATCH] Rate limit behind proxy --- app/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index 57b208e..9dc5fc4 100644 --- a/app/app.py +++ b/app/app.py @@ -1,8 +1,14 @@ from flask import Flask, render_template, jsonify, request, abort, send_from_directory from flask_swagger import swagger from flask_swagger_ui import get_swaggerui_blueprint -from flask_limiter.util import get_remote_address +def get_remote_address(): + if request.headers.getlist("X-Forwarded-For"): + ip = request.headers.getlist("X-Forwarded-For")[0] + else: + ip = request.remote_addr or '127.0.0.1' + + return ip def create_app(char_limit=-1, req_limit=-1, ga_id=None, debug=False): from app.init import boot