sphinx-doc / sphinx-autobuild

Watch a Sphinx directory and rebuild the documentation when a change is detected. Also includes a hot-reload web server.
MIT License
552 stars 83 forks source link

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

Open KyeRussell opened 5 days ago

KyeRussell commented 5 days ago

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: https://github.com/sphinx-doc/sphinx-autobuild/blob/86e2f373802417c944fda6c2930c8c3c98c20218/sphinx_autobuild/middleware.py#L11-L18

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!