Skip to content

Commit

Permalink
Fixing http-proxy error handling to not crash on error (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-zinger authored Jun 18, 2020
1 parent eea53d3 commit 86f9651
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/daemon/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Group extends EventEmitter {
this._proxy = httpProxy.createProxyServer({
xfwd: true
});

// `http-proxy` requires that at least 1 listener exists to not raise
// an exception. See https://github.com/http-party/node-http-proxy/blob/9b96cd725127a024dabebec6c7ea8c807272223d/lib/http-proxy/index.js#L119
this._proxy.on("error", err => console.error(err));
}

_output(id, data) {
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const proxy = httpProxy.createServer({
xfwd: true
});

// `http-proxy` requires that at least 1 listener exists to not raise
// an exception. See https://github.com/http-party/node-http-proxy/blob/9b96cd725127a024dabebec6c7ea8c807272223d/lib/http-proxy/index.js#L119
proxy.on("error", err => console.error(err));

// Start HTTPS proxy and HTTP server
proxy.listen(conf.port + 1);

Expand Down
7 changes: 7 additions & 0 deletions test/daemon/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,10 @@ test("group.handleConnect on port 443", t => {
sinon.assert.calledWith(tcpProxy.proxy, socket, conf.port + 1);
t.pass();
});

test("group proxy doesnt raise exception on error", t => {
const group = Group();
// This line will raise if http-proxy doesn't have at least 1 listener
group._proxy.emit("error", "an error that occured");
t.pass();
});

0 comments on commit 86f9651

Please sign in to comment.