Skip to content

Commit 3363d5a

Browse files
committed
add an env var to handle getting IP from behind a proxy and fixing rate limiting
1 parent 480a718 commit 3363d5a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This is the backend that provides access to the ClassClock database.
1818
| AUTH0_CLIENT_ID | no default | Your Auth0 Client ID |
1919
| AUTH0_CLIENT_SECRET | no default | Your Auth0 Client Secret |
2020
| SENTRY_DSN | no default | The dsn URL from the sentry.io setup in case you wish to set up error monitoring |
21-
21+
| TRUSTED_PROXY_COUNT | no default | The number of proxies that are in between users and the app itself. Setting this too high can create security problems. Setting too low can cause rate limiting to not work |
2222

2323

2424
## First time Setup

api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from common.schemas import *
1010
from auth import db_connection_string
1111
from flask_migrate import Migrate
12+
from werkzeug.middleware.proxy_fix import ProxyFix
13+
1214
from os import environ as env
1315

1416
if env.get("SENTRY_DSN"):
@@ -23,6 +25,11 @@
2325

2426
def create_app(config_filename=None):
2527
app = Flask(__name__)
28+
if env.get("TRUSTED_PROXY_COUNT"):
29+
# for example if the request goes through one proxy
30+
# before hitting your application server
31+
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=env.get("TRUSTED_PROXY_COUNT"))
32+
2633
if config_filename:
2734
app.config.from_pyfile(config_filename)
2835

0 commit comments

Comments
 (0)