04/16 Updated with domain settings in .env file

This commit is contained in:
2026-04-16 13:11:28 -04:00
parent 7bee3bfedc
commit 03c9ca088c
3 changed files with 45 additions and 15 deletions
+23 -5
View File
@@ -42,6 +42,24 @@ import openpyxl
bp = Blueprint('qr_codes', __name__)
def _get_qr_base_url():
"""
Return the authoritative base URL for QR code destination links.
Prefers the explicit QR_BASE_URL config value (set via .env / config.py).
Falls back gracefully to request.url_root if not configured.
Using an explicit QR_BASE_URL is required when the app runs behind a
reverse proxy (e.g. nginx) that can cause request.url_root to produce
a doubled hostname such as:
https://qr.govservicesinc.com,qr.govservicesinc.com/
"""
configured = current_app.config.get('QR_BASE_URL', '').rstrip('/')
if configured:
return configured + '/'
# Fallback: normalise request.url_root to avoid any trailing-slash issues
return request.url_root.rstrip('/') + '/'
# --- ADDED: helper — returns distinct (location, location_address) pairs from
# all standard QR codes, used to auto-populate the dynamic QR location list ---
def get_unique_qr_locations():
@@ -193,7 +211,7 @@ def create_qr_code():
qr_url = generate_qr_url(name, new_qr_code.id)
# Generate QR code data with the destination URL and custom styling
qr_data = f"{request.url_root}qr/{qr_url}"
qr_data = f"{_get_qr_base_url()}qr/{qr_url}"
qr_image = generate_qr_code(
data=qr_data,
fill_color=fill_color,
@@ -321,7 +339,7 @@ def import_bulk_qr_codes():
created_by=session['user_id'],
generate_qr_code_func=generate_qr_code,
generate_qr_url_func=generate_qr_url,
request_url_root=request.url_root,
request_url_root=_get_qr_base_url(),
project_lookup=project_lookup,
QRCode=QRCode,
Project=Project,
@@ -543,7 +561,7 @@ def edit_qr_code(qr_id):
# Regenerate QR code if name or styling changed
if name_changed or styling_changed:
qr_data = f"{request.url_root}qr/{qr_code.qr_url}"
qr_data = f"{_get_qr_base_url()}qr/{qr_code.qr_url}"
# Use new styling if available, otherwise use defaults
styling = get_qr_styling(qr_code)
@@ -1117,7 +1135,7 @@ def copy_qr_url(qr_id):
return jsonify({
'success': True,
'message': f'QR code URL copied to clipboard!',
'url': f"{request.url_root}qr/{qr_code.qr_url}"
'url': f"{_get_qr_base_url()}qr/{qr_code.qr_url}"
})
except Exception as e:
@@ -1140,7 +1158,7 @@ def open_qr_link(qr_id):
return jsonify({
'success': True,
'message': f'Opening QR code link...',
'url': f"{request.url_root}qr/{qr_code.qr_url}"
'url': f"{_get_qr_base_url()}qr/{qr_code.qr_url}"
})
except Exception as e: