intesso / connect-livereload

connect middleware for adding the livereload script to the response
MIT License
305 stars 53 forks source link

Remove hard-coded `/livereload.js` in place of `src` which will allow cu... #54

Closed shakyShane closed 9 years ago

shakyShane commented 9 years ago

...stom script src's to operate as expected.

Because the snip function has the hardcoded value, any attempt to use a custom src option results in the snippet being written to the response twice.

The test I added simply verifies that the src is only written once.

andineck commented 9 years ago

huh, it's been a while... right, when overwriting src, the current implementation does not work when livereload.js is renamed.

since the src string is quite bloated with host, port etc. what do you think of something like this?

var src = opt.src || "//' + (location.hostname || '" + hostname + "') + ':" + port + "/livereload.js?snipver=1";
var file = src.split('/').pop()
...
function snip(body) {
  if (!body) return false;
  return (~body.lastIndexOf(file));
}