Skip to content

Commit

Permalink
Use callbacks for proxy binding method calls.
Browse files Browse the repository at this point in the history
If an app is trying to connect to a proxy that's down, this prevents it from
freezing up and allows it to try another proxy if it hears about one.
  • Loading branch information
Emily Stark committed Aug 7, 2013
1 parent a9a99ce commit 63327b5
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions packages/webapp/webapp_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,29 @@ WebAppInternals.bindToProxy = function (proxyConfig) {
var route = process.env.ROUTE;
var host = route.split(":")[0];
var port = +route.split(":")[1];

var completedBindings = {
ddp: false,
http: false,
https: proxyConfig.securePort !== null ? false : undefined
};

var bindingDoneCallback = function (binding) {
return function (err, resp) {
if (err)
throw err;

completedBindings[binding] = true;
var completedAll = _.every(_.keys(completedBindings), function (binding) {
return (completedBindings[binding] ||
completedBindings[binding] === undefined);
});
if (completedAll)
Log("Bound to proxy.");
return completedAll;
};
};

proxy.call('bindDdp', {
pid: pid,
bindTo: ddpBindTo,
Expand All @@ -529,7 +552,7 @@ WebAppInternals.bindToProxy = function (proxyConfig) {
port: port,
pathPrefix: bindPathPrefix + '/websocket'
}
});
}, bindingDoneCallback("ddp"));
proxy.call('bindHttp', {
pid: pid,
bindTo: {
Expand All @@ -542,7 +565,7 @@ WebAppInternals.bindToProxy = function (proxyConfig) {
port: port,
pathPrefix: bindPathPrefix
}
});
}, bindingDoneCallback("http"));
if (proxyConfig.securePort !== null) {
proxy.call('bindHttp', {
pid: pid,
Expand All @@ -557,9 +580,8 @@ WebAppInternals.bindToProxy = function (proxyConfig) {
port: port,
pathPrefix: bindPathPrefix
}
});
}, bindingDoneCallback("https"));
}
Log("Bound to proxy");
};

runWebAppServer();

0 comments on commit 63327b5

Please sign in to comment.