intesso / connect-livereload

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

Enhancement Request: better if default livereload server port to be empty #85

Closed yuhere closed 1 month ago

yuhere commented 10 months ago

The code below will add <script src="//myhost.com:443/livereload.js?snipver=1" async="" defer=""></script> to a html,

const app = express();
app.use(connect_livereload({
    port: 443,
}))

However, is most commonly cases, livereload is on the same server with the app, so using an empty port should be more convenient.

const app = express();
app.use(connect_livereload())
>> <script src="//myhost.com/livereload.js?snipver=1" async="" defer=""></script>

from: (index.js)


var disableCompression = opt.disableCompression || false;
var port = opt.port || 35729;
var plugins = opt.plugins || [];

function snippet(host) { var src = opt.src || '//' + host + ':' + port + '/livereload.js?snipver=1'; return [src].concat(plugins).map(function(source) { return ''; }).join(''); }


to:
``` javascript
  var disableCompression = opt.disableCompression || false;
  var port = opt.port;
  var plugins = opt.plugins || [];

  function snippet(host) {
    var src = opt.src || '//' + host + (port ? ':' + port: '') + '/livereload.js?snipver=1';
    return [src].concat(plugins).map(function(source) {
      return '<script src="' + source + '" async="" defer=""></script>';
    }).join('');
  }