Skip to content

Commit 86f9651

Browse files
authored
Fixing http-proxy error handling to not crash on error (#7)
1 parent eea53d3 commit 86f9651

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Diff for: src/daemon/group.js

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class Group extends EventEmitter {
2424
this._proxy = httpProxy.createProxyServer({
2525
xfwd: true
2626
});
27+
28+
// `http-proxy` requires that at least 1 listener exists to not raise
29+
// an exception. See https://github.com/http-party/node-http-proxy/blob/9b96cd725127a024dabebec6c7ea8c807272223d/lib/http-proxy/index.js#L119
30+
this._proxy.on("error", err => console.error(err));
2731
}
2832

2933
_output(id, data) {

Diff for: src/daemon/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const proxy = httpProxy.createServer({
4040
xfwd: true
4141
});
4242

43+
// `http-proxy` requires that at least 1 listener exists to not raise
44+
// an exception. See https://github.com/http-party/node-http-proxy/blob/9b96cd725127a024dabebec6c7ea8c807272223d/lib/http-proxy/index.js#L119
45+
proxy.on("error", err => console.error(err));
46+
4347
// Start HTTPS proxy and HTTP server
4448
proxy.listen(conf.port + 1);
4549

Diff for: test/daemon/group.js

+7
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,10 @@ test("group.handleConnect on port 443", t => {
156156
sinon.assert.calledWith(tcpProxy.proxy, socket, conf.port + 1);
157157
t.pass();
158158
});
159+
160+
test("group proxy doesnt raise exception on error", t => {
161+
const group = Group();
162+
// This line will raise if http-proxy doesn't have at least 1 listener
163+
group._proxy.emit("error", "an error that occured");
164+
t.pass();
165+
});

0 commit comments

Comments
 (0)