Trust Caddy's X-Forwarded-Proto so external links use https
Test backoffice (smb-crm) / test (push) Successful in 1m57s

url_for(_external=True) (e.g. the owner ICS feed link, #22) was always
guessing "http" since Flask has no way to know the original request was
HTTPS when Caddy proxies to us over plain internal HTTP.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-11 23:58:57 +02:00
parent 1b8f8c1391
commit 4ad87ffaaf
+6
View File
@@ -12,6 +12,7 @@ from decimal import Decimal
from flask import Flask, jsonify, request, Response from flask import Flask, jsonify, request, Response
from waitress import serve from waitress import serve
from werkzeug.middleware.proxy_fix import ProxyFix
import booking_db as bdb import booking_db as bdb
import db import db
@@ -24,6 +25,11 @@ from owner_booking import bp as owner_booking_bp
from owner_settings import bp as owner_settings_bp from owner_settings import bp as owner_settings_bp
app = Flask(__name__, static_folder="static", static_url_path="") app = Flask(__name__, static_folder="static", static_url_path="")
# Caddy terminates TLS and proxies to us over plain HTTP, forwarding
# X-Forwarded-Proto/-Host; without this, url_for(_external=True) (e.g. the
# owner's ICS feed link, #22) always guesses "http" since Flask has no other
# way to know the original request was HTTPS. One hop of proxy (Caddy).
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
app.register_blueprint(booking_bp) app.register_blueprint(booking_bp)
app.register_blueprint(public_booking_bp) app.register_blueprint(public_booking_bp)
app.register_blueprint(manage_booking_bp) app.register_blueprint(manage_booking_bp)