Skip to content

Commit

Permalink
Consider liveReloadPrefix option which got added into tiny-lr
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparshith Nairbalige Rai committed Jul 23, 2018
1 parent b5d8e21 commit 63b8c66
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion index.js
@@ -1,5 +1,23 @@
'use strict';

function buildLiveReloadPath(prefix) {
prefix = prefix !== undefined ? prefix : '/';

var rootUrl = prefix;

// Add trailing slash
if (prefix[prefix.length - 1] !== '/') {
rootUrl = rootUrl + '/';
}

// Add leading slash
if (prefix[0] !== '/') {
rootUrl = '/' + rootUrl;
}

return rootUrl;
}

module.exports = {
name: 'live-reload-middleware',

Expand All @@ -18,10 +36,11 @@ module.exports = {
liveReloadOptions.snipver = 1;
}

var liveReloadPath = buildLiveReloadPath(options.liveReloadPrefix);
return "(function() {\n " +
(liveReloadOptions ? "window.LiveReloadOptions = " + JSON.stringify(liveReloadOptions) + ";\n " : '') +
"var srcUrl = " + (options.liveReloadJsUrl ? "'" + options.liveReloadJsUrl + "'" : "null") + ";\n " +
"var src = srcUrl || ((location.protocol || 'http:') + '//' + (location.hostname || 'localhost') + ':" + options.liveReloadPort + "/livereload.js');\n " +
"var src = srcUrl || ((location.protocol || 'http:') + '//' + (location.hostname || 'localhost') + ':" + options.liveReloadPort + liveReloadPath +"livereload.js');\n " +
"var script = document.createElement('script');\n " +
"script.type = 'text/javascript';\n " +
"script.src = src;\n " +
Expand Down

0 comments on commit 63b8c66

Please sign in to comment.