Skip to content

Allow customising browser-facing hostname, port, and protocol #185

@KyeRussell

Description

@KyeRussell

My Docker Compose-based development environment involves sphinx-autobuild sitting behind a reverse proxy. The reverse proxy serves sphinx-autobuild as HTTPS. This breaks a couple of assumptions made by sphinx-autobuild, particularly the largely hard-coded websocket setup HTML/JS snippet that it injects into the HTML response sent to the browser.

See:

def web_socket_script(ws_url: str) -> str:
# language=HTML
return f"""
<script>
const ws = new WebSocket("ws://{ws_url}/websocket-reload");
ws.onmessage = () => window.location.reload();
</script>
"""

ws_url is ultimately comprised of the 'host' and 'port' that sphinx-autobuild is running on.

I'd like to be able to override both of these values for all instances where sphinx-autobuild is sending them to the browser, for whatever reason, including this websocket setup. That way, the values can be customised to accommodate reverse proxy setups.

Also, the ws schema actually implies an insecure (non-HTTPS) connection. websocket-over-HTTPS connections use wss. I'd like to be able to forcibly tell sphinx-autobuild that, from the browser's perspective, it's being accessed in a HTTPS context, and for it to adjust its output appropriately (including using wss instead of ws.

I may get around to submitting a PR at some point. However, the described setup isn't at all unusual, so it felt worth logging here first, to help out anyone else running into the same thing, and maybe to even prompt someone to get in before I do!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions