routes: use detected base URL in usage examples

This commit is contained in:
Username
2025-12-20 05:27:10 +01:00
parent 677d3e5ba1
commit 964698428c

View File

@@ -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('/<id>')}": "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",
}