mklabs/tiny-lr — pull request #45 by Steffen185 (2014-06-27 09:47:01+00:00)
Title: Use default port 80/443 if none exists in URL

I want to use tiny-lr behind an nginx proxy on port 80/443. This has two advantages: 1) only ports 80/443 are needed and not port 35729 (firewall, port forwarding, ...). 2) I do not have to configure SSL/HTTPS in tiny-lr because SSL/HTTPS is already configured in nginx.

I'm embedding the livereload.js script like this:

Unfortunately this does not work out of the box because the livereload.js script fails to notice that it has been loaded over port 80/443. It then falls back to port 35729. The fix is easy: The default port should not be 35729 but 80 or 443 (depending on options.https).

Would this break existing setups? As I understand it: no. If you load livereload.js on a port different from 80/443 then this port is guaranteed to explicitly exist in the URL such that livereload.js would still use it:

proxy setup in nginx configuration:

location /livereload {
proxy_pass http://127.0.0.1:35729;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}