routes: use detected base URL in usage examples
All checks were successful
CI / test (push) Successful in 37s
All checks were successful
CI / test (push) Successful in 37s
This commit is contained in:
@@ -23,6 +23,22 @@ def _url(path: str) -> str:
|
|||||||
prefix = current_app.config.get("URL_PREFIX", "")
|
prefix = current_app.config.get("URL_PREFIX", "")
|
||||||
return f"{prefix}{path}"
|
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)
|
# Runtime-generated PoW secret (used if not configured)
|
||||||
_pow_secret_cache = None
|
_pow_secret_cache = None
|
||||||
|
|
||||||
@@ -341,9 +357,9 @@ def index():
|
|||||||
f"DELETE {_url('/<id>')}": "Delete paste",
|
f"DELETE {_url('/<id>')}": "Delete paste",
|
||||||
},
|
},
|
||||||
"usage": {
|
"usage": {
|
||||||
"raw": f"curl --data-binary @file.txt http://host{_url('/')}",
|
"raw": f"curl --data-binary @file.txt {_base_url()}/",
|
||||||
"pipe": f"cat file.txt | curl --data-binary @- http://host{_url('/')}",
|
"pipe": f"cat file.txt | curl --data-binary @- {_base_url()}/",
|
||||||
"json": f"curl -H 'Content-Type: application/json' -d '{{\"content\":\"...\"}}' http://host{_url('/')}",
|
"json": f"curl -H 'Content-Type: application/json' -d '{{\"content\":\"...\"}}' {_base_url()}/",
|
||||||
},
|
},
|
||||||
"note": "Use --data-binary (not -d) to preserve newlines",
|
"note": "Use --data-binary (not -d) to preserve newlines",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user