hiddentao / gulp-server-livereload

Gulp plugin to run a local webserver with livereload enabled via socket.io. Also comes with standalone command-line interface.
MIT License
93 stars 28 forks source link

Allow setting separate livereload host #27

Closed attilagyorffy closed 8 years ago

attilagyorffy commented 8 years ago

Hi,

Thank you for your work. I'm in a situation where I'd like live reload to reference a separate host other than the default. This is in order to be able to live reload apps via a local network.

This change introduces a new configuration option (with the current value as the default) to set just that.

hiddentao commented 8 years ago

Good idea.

I think the config option should be called livereload.markupHost since the value is only used in the markup and not when actually creating the livereload server. The description should read: the hostname to use for the livereload server in the injected SCRIPT tag. The default value should be: config.host.

attilagyorffy commented 8 years ago

Actually the livereload.markuphostis a better name, I agree. In regards to the default value, I was thinking maybe we could think this through:

In most cases people will be running the live reload server on the same host that they are using in the browser, let it be config.host, 'localhost' or even whatever.my.domain.is.dev.

If we specify a default of window.location.host, we could refetene the script tag relatively from the request URI. This will provide a sensible default to everyone without having to specify a default livereload.markupHost. If people need to overwrite this for whatever reason then they could specify it in the relevant configuration option.

The snippet would look similar to something I've done in the past (of course with the right parameters, but you get the idea):

<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>

Makes sense? What do you think @hiddentao?

hiddentao commented 8 years ago

@liquid I like that idea of auto-calculating the hostname from window.location.host. It would be great to do it in this PR if possible.

hiddentao commented 8 years ago

Need this myself so have merged it in.