]> littlesong.place Git - littlesongplace.git/commitdiff
Configure proxy
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 19 Jan 2025 17:15:15 +0000 (12:15 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 19 Jan 2025 17:15:15 +0000 (12:15 -0500)
main.py

diff --git a/main.py b/main.py
index fca4eefc653bb6ac4c540d9c619c0b5982ec2f30..1d13a01f2f8bfbf11e0d2470abdcc4691e3c55fa 100644 (file)
--- a/main.py
+++ b/main.py
@@ -19,6 +19,7 @@ from bleach.css_sanitizer import CSSSanitizer
 from flask import Flask, render_template, request, redirect, g, session, abort, \
         send_from_directory, flash, get_flashed_messages
 from werkzeug.utils import secure_filename
+from werkzeug.middleware.proxy_fix import ProxyFix
 
 DATA_DIR = Path(os.environ["DATA_DIR"]) if "DATA_DIR" in os.environ else Path(".")
 
@@ -41,6 +42,12 @@ app = Flask(__name__)
 app.secret_key = os.environ["SECRET_KEY"] if "SECRET_KEY" in os.environ else "dev"
 app.config["MAX_CONTENT_LENGTH"] = 50 * 1024 * 1024
 app.logger.addHandler(handler)
+if "DATA_DIR" in os.environ:
+    # Running on server behind proxy
+    app.wsgi_app = ProxyFix(
+        app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
+    )
+
 
 @app.route("/")
 def index():