Skip to content

Commit 60f716b

Browse files
committed
update create_app and config if the app is behind reverse proxy
1 parent cc522d8 commit 60f716b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

config.example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class ProductionConfig(Config):
7979
DEBUG = False
8080
DEVEL = False
8181

82+
# is production behind a reverse proxy?
83+
BEHIND_PROXY = True
84+
8285
# Set cookie behavior
8386
SESSION_COOKIE_SECURE = (True,)
8487
SESSION_COOKIE_HTTPONLY = (True,)

flowapp/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from flask_migrate import Migrate
1212
from flask_session import Session
1313
from flasgger import Swagger
14+
from werkzeug.middleware.proxy_fix import ProxyFix
15+
1416

1517
from .__about__ import __version__
1618
from .instance_config import InstanceConfig
@@ -58,6 +60,10 @@ def create_app(config_object=None):
5860
# Init swagger
5961
swagger.init_app(app)
6062

63+
# handle proxy fix
64+
if app.config.get("BEHIND_PROXY", False):
65+
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
66+
6167
from flowapp import models, constants, validators
6268
from .views.admin import admin
6369
from .views.rules import rules

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ PyMySQL>=1.0.0
1010
pytest>=7.0.0
1111
requests>=2.20.0
1212
babel>=2.7.0
13-
mysqlclient>=2.0.0
1413
email_validator>=1.1
1514
pika>=1.3.0
16-
gunicorn>=22.0.0
1715
loguru
1816
flasgger
1917
python-dotenv

0 commit comments

Comments
 (0)