diff --git a/app/api/routes.py b/app/api/routes.py index e729cfe..e5dec7c 100644 --- a/app/api/routes.py +++ b/app/api/routes.py @@ -23,6 +23,22 @@ def _url(path: str) -> str: prefix = current_app.config.get("URL_PREFIX", "") return f"{prefix}{path}" + +def _base_url() -> str: + """Detect base URL from request headers (for reverse proxy deployments).""" + scheme = ( + request.headers.get("X-Forwarded-Proto") + or request.headers.get("X-Scheme") + or request.scheme + ) + host = ( + request.headers.get("X-Forwarded-Host") + or request.headers.get("Host") + or request.host + ) + prefix = current_app.config.get("URL_PREFIX", "") + return f"{scheme}://{host}{prefix}" + # Runtime-generated PoW secret (used if not configured) _pow_secret_cache = None @@ -341,9 +357,9 @@ def index(): f"DELETE {_url('/')}": "Delete paste", }, "usage": { - "raw": f"curl --data-binary @file.txt http://host{_url('/')}", - "pipe": f"cat file.txt | curl --data-binary @- http://host{_url('/')}", - "json": f"curl -H 'Content-Type: application/json' -d '{{\"content\":\"...\"}}' http://host{_url('/')}", + "raw": f"curl --data-binary @file.txt {_base_url()}/", + "pipe": f"cat file.txt | curl --data-binary @- {_base_url()}/", + "json": f"curl -H 'Content-Type: application/json' -d '{{\"content\":\"...\"}}' {_base_url()}/", }, "note": "Use --data-binary (not -d) to preserve newlines", }