Skip to content

Commit 80120dc

Browse files
imolorheshakyShane
authored andcommitted
Added localtunnel error listener to prevent browsersync from crashing.
1 parent 429403c commit 80120dc

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/tunnel.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ module.exports = function (bs, cb) {
2424
if (err) {
2525
return cb(err);
2626
}
27+
28+
tunnel.on("error", function (err) {
29+
bs.logger.info("Localtunnel issue: " + err.message);
30+
bs.logger.info("Oops! The localtunnel appears to have disconnected. Reconnecting...");
31+
});
32+
2733
return cb(null, tunnel);
2834
});
2935
};

test/specs/e2e/server/e2e.server.tunnel.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,26 @@ describe("Tunnel e2e tests with Error", function () {
8181
browserSync(config, function (err, bs) {
8282
assert.isUndefined(bs.options.getIn(["urls", "tunnel"]));
8383
delete require.cache[tunnelPath];
84+
bs.cleanup();
8485
done();
8586
});
8687
});
87-
});
88+
89+
it("does not crash if tunnel restarts", function(done) {
90+
browserSync.reset();
91+
var config = {
92+
server: {
93+
baseDir: "test/fixtures"
94+
},
95+
open: false,
96+
tunnel: true,
97+
online: true
98+
};
99+
100+
browserSync(config, function(err, bs) {
101+
bs.tunnel.emit("error", new Error("connection refused: (check your firewall settings)"));
102+
bs.cleanup();
103+
done();
104+
});
105+
});
106+
});

0 commit comments

Comments
 (0)