Skip to content

Commit

Permalink
fix(autoload): Colon after protocol (#65)
Browse files Browse the repository at this point in the history
If protocol is explicitly specified, ensure a colon is added.
  • Loading branch information
reves authored and statianzo committed Mar 8, 2021
1 parent 3e8e219 commit a876ff4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class LiveReloadPlugin {
* @private
*/
_autoloadJs() {
const protocol = this.options.protocol;
const fullProtocol = `${protocol}${protocol ? ':' : ''}`
return (
`
// webpack-livereload-plugin
Expand All @@ -186,7 +188,7 @@ class LiveReloadPlugin {
var el = document.createElement("script");
el.id = id;
el.async = true;
el.src = "${this.options.protocol}//${this.options.hostname}:${this.options.port}/livereload.js";
el.src = "${fullProtocol}//${this.options.hostname}:${this.options.port}/livereload.js";
document.getElementsByTagName("head")[0].appendChild(el);
console.log("[Live Reload] enabled");
}());
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,19 @@ test('autoloadJs contains instanceId', function(t) {
t.end();
});

test('autoloadJs suffixes protocol with colon', function(t) {
const plugin = new LiveReloadPlugin({
protocol: 'https'
});
const [,src] = plugin._autoloadJs().match(/src\s+=\s+"(.+)"/)
t.assert(src.startsWith('https://'));
t.end();
});


test('autoloadJs suffixes empty protocol without colon', function(t) {
const plugin = new LiveReloadPlugin();
const [,src] = plugin._autoloadJs().match(/src\s+=\s+"(.+)"/)
t.assert(src.startsWith('//'));
t.end();
});

0 comments on commit a876ff4

Please sign in to comment.