diff --git a/gateway.py b/gateway.py index 7d3fd53..02a2d95 100644 --- a/gateway.py +++ b/gateway.py @@ -125,6 +125,7 @@ class GatewayHandler(BaseHTTPRequestHandler): "body": body, "cookies": cookies, "gateway_host": self.headers.get("Host", f"localhost:{GATEWAY_PORT}"), + "scheme": self.headers.get("X-Forwarded-Proto", "http"), } try: diff --git a/handlers/__init__.py b/handlers/__init__.py index f05dabb..ba91d9a 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -48,6 +48,7 @@ def _dispatch_inner(data): query = data.get("query", {}) body = data.get("body", {}) gateway_host = data.get("gateway_host", "") + scheme = data.get("scheme", "http") def extract_id(prefix): try: @@ -72,7 +73,7 @@ def _dispatch_inner(data): elif path == "/bookmark": return handle_bookmark(query) elif path == "/style": - return handle_style_form() + return handle_style_form(gateway_host=gateway_host, scheme=scheme) elif path == "/share/preview": return handle_share_preview() elif path == "/about": @@ -121,14 +122,14 @@ def _dispatch_inner(data): pid = extract_id("/delete/") return handle_delete(pid) if pid is not None else _error(400) elif path == "/style": - return handle_style_submit(body) + return handle_style_submit(body, gateway_host=gateway_host, scheme=scheme) elif path == "/style/reset": set_setting("custom_template", "") - return handle_style_form("Template reset to default.") + return handle_style_form("Template reset to default.", gateway_host=gateway_host, scheme=scheme) elif path == "/style/vacuum": from db import vacuum_db vacuum_db() - return handle_style_form("Database vacuumed.") + return handle_style_form("Database vacuumed.", gateway_host=gateway_host, scheme=scheme) elif path == "/import": return handle_import_submit(body) elif path == "/reindex": diff --git a/handlers/customize.py b/handlers/customize.py index 1f2568b..6e158ed 100644 --- a/handlers/customize.py +++ b/handlers/customize.py @@ -5,7 +5,7 @@ from ._helpers import _respond, _csrf_field, _get_bookmark_token from .subscriptions import _count_shared_pages -def handle_style_form(msg=""): +def handle_style_form(msg="", gateway_host="", scheme="http"): template = get_setting("custom_template") or DEFAULT_TEMPLATE name = get_site_name() sharing = get_setting("sharing_enabled", "0") @@ -135,7 +135,7 @@ def handle_style_form(msg=""): f"" f"
Drag this link to your bookmarks bar. Click it on any page to index it instantly.
" - f'' + f'r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}
' f"